-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN13023.cpp
49 lines (41 loc) · 897 Bytes
/
N13023.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
#include <stdio.h>
#include <vector>
using namespace std;
vector<vector<int>> T;
vector<bool> visit;
int dfs(int n,int len);
int main(){
int n,m;
int f1,f2;
int result;
scanf("%d %d",&n,&m);
T.resize(n);
for(int i = 0; i<m;i++){
scanf("%d %d",&f1,&f2);
T[f1].push_back(f2);
T[f2].push_back(f1);
}
for (int i = 0 ;i<n;i++){
visit.assign(n, false);
result = dfs(i, 0);
if(result >= 4){
printf("1\n");
return 0;
}
}
printf("0\n");
return 0;
}
int dfs(int node,int len){
visit[node] = true;
if (len >=4)
return len;
int ans = len;
for(int i = 0;i<T[node].size();i++){
if(visit[T[node][i]] == false){
ans = max(ans,dfs(T[node][i],len+1));
}
}
visit[node] = false;
return ans;
}