-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_13023
More file actions
69 lines (58 loc) · 1.71 KB
/
BAEKJOON_13023
File metadata and controls
69 lines (58 loc) · 1.71 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main {
public static ArrayList<Integer>[] list;
public static boolean[] v;
public static boolean ok=false;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
v=new boolean[N];
list = new ArrayList[N];
for(int i=0; i<N; i++){
list[i]=new ArrayList<>();
}
for(int i=0; i<M; i++){
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
list[x].add(y);
list[y].add(x);
}
for(int i=0; i<N; i++){
//모든 정점을 확인
if(!ok){
dfs(i,1);
}
}
if(ok){
bw.write("1");
}else{
bw.write("0");
}
bw.flush();
bw.close();
br.close();
}
public static void dfs(int start,int depth){
if(depth==5){
ok=true;
return;
}
v[start]=true;
for(int i : list[start]){
int next = i;
if(!v[next]){
dfs(next,depth+1);
}
}
v[start]=false;
}
}