-
Notifications
You must be signed in to change notification settings - Fork 0
/
P13023.cpp
55 lines (41 loc) · 869 Bytes
/
P13023.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
#include <iostream>
#include <vector>
using namespace std;
vector<int> graph[2001];
int check[2001] = {};
int flag = 0;
void dfs(int s, int count) {
if(!flag && count == 5) {
cout << 1;
flag = 1;
return;
}
check[s] = 1;
for (int i = 0; i < graph[s].size(); i++) {
int a = graph[s][i];
if (check[a]) continue;
if(flag) break;
dfs(a, count + 1);
}
check[s] = 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for (int i = 0; i < N; i++) {
if(check[i]) continue;
dfs(i, 1);
if(flag) return 0;
}
cout << 0;
return 0;
}