-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13023_ABCDE.cpp
56 lines (48 loc) · 920 Bytes
/
13023_ABCDE.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
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 2001
vector<int> graph[MAX];
int visited[MAX] = {
0,
};
int result = 0;
int n, m;
void dfs(int node, int cnt) {
if (cnt == 4) {
result = 1;
return;
}
for (int i = 0; i < graph[node].size(); i++) {
int next_node = graph[node][i];
if (!visited[next_node]) {
visited[next_node] = 1;
dfs(next_node, cnt + 1);
visited[next_node] = 0;
}
}
}
int main() {
cin >> n >> m;
int person1, person2;
for (int i = 0; i < m; i++) {
cin >> person1 >> person2;
graph[person1].push_back(person2);
graph[person2].push_back(person1);
}
for (int i = 0; i < n; i++) {
if (!visited[i]) {
visited[i] = 1;
dfs(i, 0);
visited[i] = 0;
if (result) {
break;
}
}
}
cout << result;
return 0;
}