結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-02-24 22:08:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,844 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 107,068 KB
最終ジャッジ日時 2023-09-15 10:13:42
合計ジャッジ時間 21,964 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,336 KB
testcase_01 AC 72 ms
71,276 KB
testcase_02 AC 613 ms
87,816 KB
testcase_03 AC 611 ms
87,960 KB
testcase_04 AC 530 ms
87,836 KB
testcase_05 AC 604 ms
87,980 KB
testcase_06 AC 580 ms
87,840 KB
testcase_07 AC 307 ms
87,440 KB
testcase_08 AC 251 ms
87,736 KB
testcase_09 AC 217 ms
87,304 KB
testcase_10 AC 223 ms
87,460 KB
testcase_11 AC 218 ms
87,400 KB
testcase_12 AC 163 ms
85,812 KB
testcase_13 AC 392 ms
97,272 KB
testcase_14 AC 134 ms
84,636 KB
testcase_15 AC 381 ms
97,724 KB
testcase_16 AC 392 ms
96,332 KB
testcase_17 AC 381 ms
96,992 KB
testcase_18 AC 400 ms
96,748 KB
testcase_19 AC 391 ms
97,628 KB
testcase_20 AC 389 ms
96,352 KB
testcase_21 AC 395 ms
98,076 KB
testcase_22 AC 1,727 ms
105,664 KB
testcase_23 AC 1,840 ms
105,484 KB
testcase_24 AC 1,821 ms
105,676 KB
testcase_25 AC 1,844 ms
106,444 KB
testcase_26 AC 1,838 ms
107,068 KB
testcase_27 AC 226 ms
92,188 KB
testcase_28 AC 221 ms
92,420 KB
testcase_29 AC 228 ms
92,320 KB
testcase_30 AC 232 ms
92,396 KB
testcase_31 AC 233 ms
92,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, m = map(int, input().split())

edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    y = int(input())
    edges[a].append((b, y))
    edges[b].append((a, y))
    
X = [0] * n
for k in range(30):
    bi = [-1] * n
    for i in range(n):
        if bi[i] != -1:
            continue
        bi[i] = 0
        stack = [i]
        while stack:
            pos = stack.pop()
            for npos, y in edges[pos]:
                if y >> k & 1:
                    x = 1
                else:
                    x = 0
                if bi[npos] == -1:
                    bi[npos] = bi[pos] ^ x
                    X[npos] ^= bi[npos] << k
                    stack.append(npos)
                elif bi[npos] != bi[pos] ^ x:
                    print(-1)
                    exit()
print(*X)
0