結果

問題 No.1420 国勢調査 (Easy)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-06 10:32:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 94,528 KB
最終ジャッジ日時 2024-04-16 22:54:21
合計ジャッジ時間 11,194 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,504 KB
testcase_01 AC 46 ms
54,016 KB
testcase_02 AC 290 ms
87,424 KB
testcase_03 AC 289 ms
87,808 KB
testcase_04 AC 293 ms
87,936 KB
testcase_05 AC 286 ms
88,192 KB
testcase_06 AC 293 ms
87,936 KB
testcase_07 AC 280 ms
87,552 KB
testcase_08 AC 276 ms
87,296 KB
testcase_09 AC 294 ms
87,680 KB
testcase_10 AC 262 ms
86,400 KB
testcase_11 AC 270 ms
86,400 KB
testcase_12 AC 148 ms
84,480 KB
testcase_13 AC 195 ms
84,896 KB
testcase_14 AC 145 ms
84,224 KB
testcase_15 AC 194 ms
85,148 KB
testcase_16 AC 202 ms
85,124 KB
testcase_17 AC 198 ms
85,124 KB
testcase_18 AC 202 ms
85,112 KB
testcase_19 AC 207 ms
84,864 KB
testcase_20 AC 196 ms
85,120 KB
testcase_21 AC 196 ms
84,992 KB
testcase_22 AC 419 ms
94,528 KB
testcase_23 AC 390 ms
94,464 KB
testcase_24 AC 404 ms
94,336 KB
testcase_25 AC 399 ms
94,336 KB
testcase_26 AC 406 ms
94,404 KB
testcase_27 AC 301 ms
93,312 KB
testcase_28 AC 301 ms
93,056 KB
testcase_29 AC 304 ms
92,928 KB
testcase_30 AC 309 ms
93,312 KB
testcase_31 AC 303 ms
92,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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