結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-02-24 22:09:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,623 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 105,804 KB
最終ジャッジ日時 2023-09-15 10:14:09
合計ジャッジ時間 18,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,248 KB
testcase_01 AC 70 ms
71,172 KB
testcase_02 AC 452 ms
87,752 KB
testcase_03 AC 471 ms
88,480 KB
testcase_04 AC 418 ms
88,400 KB
testcase_05 AC 468 ms
88,452 KB
testcase_06 AC 470 ms
88,728 KB
testcase_07 AC 276 ms
87,428 KB
testcase_08 AC 245 ms
87,740 KB
testcase_09 AC 213 ms
87,220 KB
testcase_10 AC 215 ms
87,360 KB
testcase_11 AC 211 ms
87,152 KB
testcase_12 AC 157 ms
85,664 KB
testcase_13 AC 332 ms
97,092 KB
testcase_14 AC 122 ms
84,232 KB
testcase_15 AC 337 ms
97,128 KB
testcase_16 AC 334 ms
96,672 KB
testcase_17 AC 334 ms
97,448 KB
testcase_18 AC 335 ms
96,636 KB
testcase_19 AC 340 ms
97,560 KB
testcase_20 AC 339 ms
97,360 KB
testcase_21 AC 343 ms
97,432 KB
testcase_22 AC 1,434 ms
105,412 KB
testcase_23 AC 1,623 ms
105,804 KB
testcase_24 AC 1,427 ms
104,620 KB
testcase_25 AC 1,601 ms
105,004 KB
testcase_26 AC 1,529 ms
105,384 KB
testcase_27 AC 274 ms
91,948 KB
testcase_28 AC 210 ms
91,788 KB
testcase_29 AC 211 ms
91,820 KB
testcase_30 AC 214 ms
91,880 KB
testcase_31 AC 216 ms
92,192 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))
pow2 = [1 << i for i in range(30)]
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
                    if bi[npos]:
                        X[npos] ^= pow2[k]
                    stack.append(npos)
                elif bi[npos] != bi[pos] ^ x:
                    print(-1)
                    exit()
print(*X)
0