-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1744.java
More file actions
64 lines (50 loc) · 1.09 KB
/
P1744.java
File metadata and controls
64 lines (50 loc) · 1.09 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
package BOJ;
import java.util.*;
public class P1744 {
static ArrayList<Integer>[] graph;
static int[] color;
public static void dfs(int vertax, int c){
color[vertax] = c;
for(int x : graph[vertax]){
if(color[x]==0){
dfs(x,3-c);
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test_case = sc.nextInt();
while(test_case-- > 0){
int vertax = sc.nextInt();
int edge = sc.nextInt();
graph = (ArrayList<Integer>[]) new ArrayList[20001];
color = new int[20001];
for(int i=1;i<=vertax;i++){
graph[i] = new ArrayList<Integer>();
}
for(int i=0;i<edge;i++){
int start = sc.nextInt();
int last = sc.nextInt();
graph[start].add(last);
graph[last].add(start);
}
for(int i=1;i<=vertax;i++){
if(color[i]==0){
dfs(i,1);
}
}
boolean ok = true;
for(int i=1;i<=vertax;i++){
for(int j : graph[i]){
if(color[i]==color[j]){
ok = false;
}
}
}
if(ok==true)
System.out.println("YES");
else
System.out.println("NO");
}
}
}