結果

問題 No.1420 国勢調査 (Easy)
ユーザー convexineq
提出日時 2021-03-05 22:29:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 614 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 98,040 KB
最終ジャッジ日時 2024-10-07 03:03:35
合計ジャッジ時間 11,842 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 18 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    l,r = map(int,input().split())
    y = int(input())
    g[l-1].append((r-1,y))
    g[r-1].append((l-1,y))

res = [-1]*n
ok = 1
for i in range(n):
    if res[i] == -1:
        res[i] = 0
        st = [i]
        while st:
            v = st.pop()
            for c,d in g[v]:
                if res[c] == -1:
                    res[c] = d ^ res[v]
                    st.append(c)
                else:
                    if res[c] != d ^ res[v]:
                        ok = 0

if ok:
    print(*res,sep="\n")
else:
    print("No")
0