結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー |
|
提出日時 | 2023-02-03 23:31:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 368 ms / 2,000 ms |
コード長 | 599 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 171,768 KB |
最終ジャッジ日時 | 2024-07-02 21:34:18 |
合計ジャッジ時間 | 11,700 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
n = int(input())e = [[] for i in range(n)]for _ in range(n-1):a,b = [int(x)-1 for x in input().split()]e[a].append(b)e[b].append(a)C = list(map(int,input().split()))ans = 0topo = []vis = [0]*npar = [-1]*nq = [0]vis[0] = 1while q:now = q.pop()topo.append(now)for nex in e[now]:if vis[nex]:continuevis[nex] = 1par[nex] = nowq.append(nex)for now in topo[::-1]:if now == 0:breakif C[now]:continueC[now] = 1C[par[now]] ^= 1ans += 1if C[0] == 0:ans = -1print(ans)