제출 #986214

#제출 시각아이디문제언어결과실행 시간메모리
986214dorjderemThe Xana coup (BOI21_xanadu)Pypy 3
0 / 100
1072 ms326696 KiB
from collections import defaultdict import sys n = int(input()) mp = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) mp[a-1].append(b-1) mp[b-1].append(a-1) a = list(map(int,input().split())) for i in range(n): a[i] = True if a[i] == 1 else False can = False for i in range(n): q = [] q.append([i, a]) level = 0 while q: l = len(q) for _ in range(l): top = q.pop(0) if not any(top[1]): can = True print(level) sys.exit() cp = top[1][:] cp[top[0]] = not cp[top[0]] for nxt in mp[top[0]]: cp[nxt] = not cp[nxt] for j in range(n): q.append([j, cp]) level += 1 if level >= 10: break if not can: print("IMPOSSIBLE")
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...