-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13023.cpp
54 lines (47 loc) · 1.09 KB
/
13023.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
#include <iostream>
#include <vector>
using namespace std;
int N, M;
vector<int> v[2001];
vector<bool> check(2001, false);
void dfs(vector<int> list){
int now = list.back();
if(list.size() > 1){
// 마지막인 새로 추가한 원소므로 check x
for(int i = 0; i <= list.size() - 2; i++){
if(list[i] == now)
return;
}
if(list.size() == 5){
cout << 1 << '\n';
exit(0);
}
}
for(int i = 0; i < v[now].size(); i++){
list.push_back(v[now][i]);
dfs(list);
list.pop_back();
}
return;
}
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> N >> M;
for(int i = 0; i < M; i++){
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
check[a] = true;
check[b] = true;
}
vector<int> list;
for(int i = 0; i < check.size(); i++){
if(!check[i]) continue;
list.push_back(i);
dfs(list);
list.pop_back();
}
cout << 0 << '\n';
return 0;
}