-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path977E.cpp
More file actions
79 lines (46 loc) · 915 Bytes
/
977E.cpp
File metadata and controls
79 lines (46 loc) · 915 Bytes
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
vector <ll> grafo[300000];
bool encontrou[300000];
vector <ll> passou;
void dfs(int v){
passou.pb(v);
encontrou[v] = true;
for(int i=0;i<grafo[v].size();i++){
ll adj = grafo[v][i];
if(!encontrou[adj]){
dfs(adj);
}
}
}
int main(){
int n,m;
cin >> n >> m;
for(int i=0;i<m;i++){
ll a,b;
cin >> a >> b;
grafo[a].pb(b);
grafo[b].pb(a);
}
ll ans = 0;
for(int i=1;i<=n;i++){
if(!encontrou[i]){
passou.clear();
dfs(i);
bool So2 = true;
for(int i=0;i<passou.size();i++){
if(grafo[ passou[i] ].size() != 2){
So2 = false;
break;
}
}
if(So2){
ans++;
}
}
}
cout << ans << endl;
return 0;
}