結果
| 問題 |
No.1420 国勢調査 (Easy)
|
| コンテスト | |
| ユーザー |
nephrologist
|
| 提出日時 | 2021-03-05 23:50:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,031 bytes |
| コンパイル時間 | 218 ms |
| コンパイル使用メモリ | 81,948 KB |
| 実行使用メモリ | 113,592 KB |
| 最終ジャッジ日時 | 2024-10-07 06:00:26 |
| 合計ジャッジ時間 | 13,074 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 28 WA * 2 |
ソースコード
from collections import defaultdict
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
memo = defaultdict(lambda: defaultdict(int))
for _ in range(m):
a, b = map(int, input().split())
y = int(input())
a, b = a - 1, b - 1
graph[a].append(b)
graph[b].append(a)
if a > b:
b, a = a, b
memo[a][b] = y
used = [0] * n
ans = [-1] * n
for i in range(n):
if not used[i]:
stack = [i]
used[i] = 1
ans[i] = 0
while stack:
v = stack.pop()
now = ans[v]
for u in graph[v]:
if u < v:
temp = memo[u][v]
else:
temp = memo[v][u]
if used[u]:
if ans[u] ^ ans[v] == temp:
continue
else:
print(-1)
exit()
used[u] = 1
ans[u] = temp ^ ans[v]
stack.append(u)
for a in ans:
print(a)
nephrologist