結果

問題 No.1420 国勢調査 (Easy)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-06 10:30:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,104 KB
最終ジャッジ日時 2024-04-16 22:53:15
合計ジャッジ時間 10,841 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,888 KB
testcase_01 AC 46 ms
53,888 KB
testcase_02 AC 294 ms
87,936 KB
testcase_03 AC 290 ms
87,808 KB
testcase_04 AC 280 ms
88,320 KB
testcase_05 AC 286 ms
87,936 KB
testcase_06 AC 291 ms
87,680 KB
testcase_07 AC 274 ms
87,808 KB
testcase_08 AC 273 ms
87,552 KB
testcase_09 AC 276 ms
87,808 KB
testcase_10 AC 265 ms
86,144 KB
testcase_11 AC 261 ms
86,656 KB
testcase_12 AC 148 ms
85,120 KB
testcase_13 AC 187 ms
85,420 KB
testcase_14 AC 142 ms
85,376 KB
testcase_15 AC 187 ms
85,632 KB
testcase_16 AC 195 ms
85,264 KB
testcase_17 AC 191 ms
85,376 KB
testcase_18 AC 196 ms
85,396 KB
testcase_19 AC 193 ms
85,392 KB
testcase_20 AC 195 ms
85,504 KB
testcase_21 AC 188 ms
84,880 KB
testcase_22 AC 411 ms
95,104 KB
testcase_23 AC 385 ms
94,720 KB
testcase_24 AC 402 ms
94,592 KB
testcase_25 AC 395 ms
94,720 KB
testcase_26 AC 405 ms
95,104 KB
testcase_27 AC 294 ms
93,824 KB
testcase_28 AC 300 ms
94,080 KB
testcase_29 AC 302 ms
93,952 KB
testcase_30 AC 298 ms
94,080 KB
testcase_31 AC 298 ms
93,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    y = int(input())
    a -= 1
    b -= 1
    e[a].append((b,y))
    e[b].append((a,y))

ans = [0]*n
use = [0]*n

for i in range(n):
    if use[i]:
        continue
    q = deque([i])
    use[i] = 1
    while q:
        now = q.popleft()
        for nex,y in e[now]:
            if use[nex]:
                if ans[now]^ans[nex] != y:
                    print(-1)
                    exit()
                continue
            use[nex] = 1
            ans[nex] = y^ans[now]
            q.append(nex)
for i in ans:
    print(i)
0