結果
| 問題 |
No.1420 国勢調査 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-06 10:32:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 395 ms / 2,000 ms |
| コード長 | 638 bytes |
| コンパイル時間 | 421 ms |
| コンパイル使用メモリ | 82,464 KB |
| 実行使用メモリ | 94,540 KB |
| 最終ジャッジ日時 | 2024-10-08 05:05:52 |
| 合計ジャッジ時間 | 10,610 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
y = int(input())
e[a].append((b,y))
e[b].append((a,y))
ans = [-1]*(n+1)
for i in range(1,n+1):
if ans[i] >= 0:
continue
q = deque([i])
ans[i] = 0
while q:
now = q.popleft()
for nex,y in e[now]:
if ans[nex] >= 0:
if ans[now]^ans[nex] != y:
print(-1)
exit()
continue
ans[nex] = y^ans[now]
q.append(nex)
for i in ans[1:]:
print(i)