-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABCDE.java
More file actions
67 lines (52 loc) · 1.03 KB
/
ABCDE.java
File metadata and controls
67 lines (52 loc) · 1.03 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
package graph;
import java.util.ArrayList;
import java.util.Scanner;
public class ABCDE {
static ArrayList<Integer>[] a;
static boolean[] c;
static int m;
static boolean ans;
public static void dfs(int x, int cnt) {
if(cnt == m) {
ans = true;
return;
}
c[x] = true;
for (int y : a[x]) {
if (c[y] == false) {
dfs(y, cnt+1);
}
if(ans) {
return;
}
}
c[x] = false;
}
public static void main(String[] args) {
//#13023_ABCDE
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
m = sc.nextInt();
a = (ArrayList<Integer>[]) new ArrayList[n+1];
for(int i =0; i<=n; i++) {
a[i] = new ArrayList<Integer>();
}
for(int i = 0; i<m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
a[x].add(y);
a[y].add(x);
}
c = new boolean[n+1];
for(int i =0; i<n; i++) {
dfs(i,1);
if(ans) break;
}
if(ans) {
System.out.print("1");
}
else {
System.out.print("0");
}
}
}