結果

問題 No.1420 国勢調査 (Easy)
ユーザー ああいいああいい
提出日時 2022-03-12 15:54:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 94,524 KB
最終ジャッジ日時 2023-10-16 23:29:00
合計ジャッジ時間 13,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,564 KB
testcase_01 AC 34 ms
53,564 KB
testcase_02 AC 252 ms
87,596 KB
testcase_03 AC 245 ms
86,372 KB
testcase_04 AC 244 ms
86,388 KB
testcase_05 AC 246 ms
86,348 KB
testcase_06 AC 254 ms
87,612 KB
testcase_07 AC 239 ms
87,488 KB
testcase_08 AC 233 ms
87,404 KB
testcase_09 AC 234 ms
87,400 KB
testcase_10 AC 233 ms
86,172 KB
testcase_11 AC 237 ms
86,160 KB
testcase_12 AC 115 ms
81,680 KB
testcase_13 AC 151 ms
84,684 KB
testcase_14 AC 112 ms
81,668 KB
testcase_15 AC 150 ms
84,740 KB
testcase_16 AC 154 ms
84,832 KB
testcase_17 AC 149 ms
84,792 KB
testcase_18 AC 149 ms
84,692 KB
testcase_19 AC 148 ms
84,828 KB
testcase_20 AC 151 ms
84,768 KB
testcase_21 AC 151 ms
84,760 KB
testcase_22 AC 342 ms
94,228 KB
testcase_23 AC 348 ms
94,524 KB
testcase_24 AC 337 ms
94,132 KB
testcase_25 AC 344 ms
94,184 KB
testcase_26 AC 345 ms
94,524 KB
testcase_27 AC 262 ms
91,716 KB
testcase_28 AC 261 ms
91,708 KB
testcase_29 AC 263 ms
91,720 KB
testcase_30 AC 265 ms
91,724 KB
testcase_31 AC 262 ms
91,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    a,b = map(int,input().split())
    y = int(input())
    G[a].append((b,y))
    G[b].append((a,y))

memo = [-1] * (N+1)
import sys
for i in range(1,N+1):
    if memo[i] != -1:continue
    memo[i] = 0
    stack = [i]
    while stack:
        now = stack.pop()
        for v,y in G[now]:
            if memo[v] == -1:
                memo[v] = memo[now] ^ y
                stack.append(v)
            else:
                if memo[v] != memo[now] ^ y:
                    print(-1)
                    exit()
for i in memo[1:]:
    print(i)
0