結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-02-24 22:06:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,616 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,075 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 108,144 KB
最終ジャッジ日時 2023-09-15 10:03:30
合計ジャッジ時間 23,641 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,108 KB
testcase_01 AC 73 ms
71,544 KB
testcase_02 AC 552 ms
89,452 KB
testcase_03 AC 540 ms
89,596 KB
testcase_04 AC 504 ms
89,656 KB
testcase_05 AC 594 ms
89,404 KB
testcase_06 AC 542 ms
89,704 KB
testcase_07 AC 351 ms
89,192 KB
testcase_08 AC 302 ms
88,904 KB
testcase_09 AC 275 ms
88,636 KB
testcase_10 AC 268 ms
87,656 KB
testcase_11 AC 268 ms
87,588 KB
testcase_12 AC 204 ms
87,416 KB
testcase_13 AC 389 ms
98,356 KB
testcase_14 AC 170 ms
85,912 KB
testcase_15 AC 369 ms
98,324 KB
testcase_16 AC 374 ms
98,380 KB
testcase_17 AC 375 ms
99,580 KB
testcase_18 AC 402 ms
98,860 KB
testcase_19 AC 375 ms
98,896 KB
testcase_20 AC 379 ms
98,444 KB
testcase_21 AC 382 ms
98,176 KB
testcase_22 AC 1,419 ms
106,708 KB
testcase_23 AC 1,353 ms
106,772 KB
testcase_24 AC 1,443 ms
106,044 KB
testcase_25 AC 1,545 ms
108,144 KB
testcase_26 AC 1,616 ms
106,524 KB
testcase_27 AC 334 ms
95,320 KB
testcase_28 AC 307 ms
95,060 KB
testcase_29 AC 305 ms
95,064 KB
testcase_30 AC 316 ms
95,296 KB
testcase_31 AC 318 ms
95,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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