diff --git "a/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" "b/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" new file mode 100644 index 00000000..34b5a842 --- /dev/null +++ "b/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" @@ -0,0 +1,43 @@ +from sys import * +from collections import * + + +def bfs(start): + q = deque([start]) + groups[start] = 1 + + while q: + curr = q.popleft() + visited[curr] = True + + for adj in graph[curr]: + if visited[adj]: + continue + + if not groups[adj]: + groups[adj] = -groups[curr] + q.append(adj) + elif groups[adj] == groups[curr]: + return False + return True + + +for _ in range(int(stdin.readline())): + V, E = map(int, stdin.readline().split()) + graph = [[] for i in range(V + 1)] + + for _ in range(E): + a, b = map(int, stdin.readline().split()) + graph[a].append(b) + graph[b].append(a) + + groups = [0] * (V + 1) + visited = [False] * (V + 1) + result = None + + for i in range(1, V + 1): + if groups[i] == 0 and not bfs(i): + result = 'NO' + break + + print('YES' if not result else result)