-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ13023.java
More file actions
49 lines (42 loc) · 888 Bytes
/
Copy pathBOJ13023.java
File metadata and controls
49 lines (42 loc) · 888 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
47
48
49
package day7.graph;
import java.util.ArrayList;
import java.util.Scanner;
public class BOJ13023 {
static int N, M;
static int cnt=0;
static ArrayList<Integer>[] adjList;
static boolean[] visited;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
N=sc.nextInt();
M=sc.nextInt();
adjList=new ArrayList[N];
visited=new boolean[N];
for (int i = 0; i < N; i++) {
adjList[i]=new ArrayList<>();
}
for (int i = 0; i < M; i++) {
int from=sc.nextInt();
int to=sc.nextInt();
adjList[from].add(to);
adjList[to].add(from);
}
for (int i = 0; i < N; i++) {
DFS(i,1);
}
System.out.println(cnt);
}
private static void DFS(int curr, int d) {
visited[curr]=true;
if(d==5) {
cnt=1;
return;
}
for (int node : adjList[curr]) {
if(!visited[node]) {
DFS(node, d+1);
}
}
visited[curr]=false;
}
}