-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_13023.cpp
More file actions
46 lines (40 loc) · 809 Bytes
/
BOJ_13023.cpp
File metadata and controls
46 lines (40 loc) · 809 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
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<vector<int>> isFriend;
vector<bool> isVisited;
int search(int index) {
if (isVisited[index])
return 0;
isVisited[index] = true;
int maxLength = 0;
for (auto iter : isFriend[index]) {
int length = search(iter);
if (length > 4)
return 999;
maxLength = length > maxLength ? length : maxLength;
}
isVisited[index] = false;
return maxLength + 1;
}
int main(void) {
int m;
cin >> n >> m;
isVisited.assign(n, false);
isFriend.assign(n, vector<int>(0));
while (m--) {
int a, b;
cin >> a >> b;
isFriend[a].push_back(b);
isFriend[b].push_back(a);
}
for (int i = 0; i < n; i++) {
if (search(i) >= 5) {
cout << 1;
return 0;
}
}
cout << 0;
return 0;
}