結果

問題 No.1420 国勢調査 (Easy)
コンテスト
ユーザー aaaaaaaaaa2230
提出日時 2021-03-06 10:32:57
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 125 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 100,148 KB
最終ジャッジ日時 2026-04-24 12:37:13
合計ジャッジ時間 7,449 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0