結果

問題 No.1420 国勢調査 (Easy)
ユーザー nephrologistnephrologist
提出日時 2021-03-05 23:47:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 114,148 KB
最終ジャッジ日時 2024-04-16 11:53:15
合計ジャッジ時間 15,438 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,376 KB
testcase_01 WA -
testcase_02 AC 384 ms
90,132 KB
testcase_03 AC 372 ms
89,940 KB
testcase_04 AC 371 ms
90,008 KB
testcase_05 AC 374 ms
89,744 KB
testcase_06 AC 385 ms
90,492 KB
testcase_07 AC 366 ms
90,020 KB
testcase_08 AC 376 ms
90,004 KB
testcase_09 AC 380 ms
89,936 KB
testcase_10 AC 388 ms
89,812 KB
testcase_11 AC 362 ms
90,008 KB
testcase_12 WA -
testcase_13 AC 208 ms
88,192 KB
testcase_14 WA -
testcase_15 AC 214 ms
88,064 KB
testcase_16 AC 211 ms
87,936 KB
testcase_17 AC 213 ms
87,808 KB
testcase_18 AC 210 ms
88,448 KB
testcase_19 AC 207 ms
87,808 KB
testcase_20 AC 215 ms
88,064 KB
testcase_21 AC 210 ms
88,060 KB
testcase_22 AC 582 ms
113,424 KB
testcase_23 AC 568 ms
113,396 KB
testcase_24 AC 557 ms
112,572 KB
testcase_25 AC 575 ms
113,260 KB
testcase_26 AC 573 ms
113,628 KB
testcase_27 AC 602 ms
113,412 KB
testcase_28 AC 596 ms
113,540 KB
testcase_29 AC 642 ms
114,148 KB
testcase_30 AC 599 ms
113,768 KB
testcase_31 AC 599 ms
114,048 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)
                        break
                used[u] = 1
                ans[u] = temp ^ ans[v]
                stack.append(u)
for a in ans:
    print(a)
0