-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path70725633.cpp
57 lines (56 loc) · 1.14 KB
/
70725633.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
vector<int> neigh[200000+5];
vector< vector<int> > sub;
int n,m;
int mark[200000+5];
set<int> unmarked;
void visit(int index)
{
mark[index]=1;
unmarked.erase(index);
sub[ sub.size()-1 ].push_back(index);
//cout<<" i pushed "<<index<<endl;
for(int i=0;i<neigh[index].size();i++)
{
if( mark[ neigh[index][i] ]==0 )
visit( neigh[index][i] );
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) unmarked.insert(i);
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
neigh[a].push_back(b);
neigh[b].push_back(a);
}
while(unmarked.size()>0)
{
vector<int> a;
sub.push_back(a);
visit( (int)*(unmarked.begin()) );
}
/*for(int i=0;i<sub.size();i++)
{
for(int j=0;j<sub[i].size();j++)
{
cout<<sub[i][j]<<" ";
}
cout<<endl;
}*/
int t=sub.size();
for(auto u:sub){
for(auto v:u){
if(neigh[v].size()!=2){
t--;
break;
}
}
}
cout<<t<<endl;
return 0;
}