結果

問題 No.1420 国勢調査 (Easy)
ユーザー nephrologistnephrologist
提出日時 2021-03-05 23:50:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 113,644 KB
最終ジャッジ日時 2024-04-16 11:55:25
合計ジャッジ時間 12,627 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,760 KB
testcase_01 WA -
testcase_02 AC 358 ms
90,264 KB
testcase_03 AC 343 ms
90,200 KB
testcase_04 AC 336 ms
90,128 KB
testcase_05 AC 366 ms
89,748 KB
testcase_06 AC 350 ms
90,504 KB
testcase_07 AC 305 ms
89,892 KB
testcase_08 AC 319 ms
89,932 KB
testcase_09 AC 300 ms
89,808 KB
testcase_10 AC 310 ms
89,980 KB
testcase_11 AC 301 ms
90,020 KB
testcase_12 WA -
testcase_13 AC 184 ms
88,052 KB
testcase_14 WA -
testcase_15 AC 195 ms
88,156 KB
testcase_16 AC 195 ms
88,224 KB
testcase_17 AC 194 ms
88,136 KB
testcase_18 AC 190 ms
88,192 KB
testcase_19 AC 185 ms
88,200 KB
testcase_20 AC 193 ms
88,280 KB
testcase_21 AC 183 ms
88,148 KB
testcase_22 AC 545 ms
113,204 KB
testcase_23 AC 530 ms
113,644 KB
testcase_24 AC 524 ms
112,696 KB
testcase_25 AC 551 ms
113,256 KB
testcase_26 AC 541 ms
113,596 KB
testcase_27 AC 383 ms
110,556 KB
testcase_28 AC 364 ms
110,208 KB
testcase_29 AC 389 ms
111,080 KB
testcase_30 AC 387 ms
110,524 KB
testcase_31 AC 374 ms
110,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
memo = defaultdict(lambda: defaultdict(int))
for _ in range(m):
    a, b = map(int, input().split())
    y = int(input())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)
    if a > b:
        b, a = a, b
    memo[a][b] = y


used = [0] * n
ans = [-1] * n
for i in range(n):
    if not used[i]:
        stack = [i]
        used[i] = 1
        ans[i] = 0
        while stack:
            v = stack.pop()
            now = ans[v]
            for u in graph[v]:
                if u < v:
                    temp = memo[u][v]
                else:
                    temp = memo[v][u]
                if used[u]:
                    if ans[u] ^ ans[v] == temp:
                        continue
                    else:
                        print(-1)
                        exit()
                used[u] = 1
                ans[u] = temp ^ ans[v]
                stack.append(u)
for a in ans:
    print(a)
0