結果

問題 No.1420 国勢調査 (Easy)
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-15 21:09:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 48,512 KB
最終ジャッジ日時 2024-04-25 00:32:48
合計ジャッジ時間 16,864 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,496 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 518 ms
36,480 KB
testcase_03 AC 494 ms
36,224 KB
testcase_04 AC 497 ms
36,352 KB
testcase_05 AC 501 ms
36,480 KB
testcase_06 AC 516 ms
36,480 KB
testcase_07 AC 401 ms
36,224 KB
testcase_08 AC 399 ms
36,096 KB
testcase_09 AC 374 ms
35,968 KB
testcase_10 AC 405 ms
36,224 KB
testcase_11 AC 374 ms
36,096 KB
testcase_12 AC 109 ms
21,376 KB
testcase_13 AC 215 ms
24,192 KB
testcase_14 AC 106 ms
21,376 KB
testcase_15 AC 221 ms
24,192 KB
testcase_16 AC 221 ms
24,320 KB
testcase_17 AC 223 ms
24,192 KB
testcase_18 AC 220 ms
24,192 KB
testcase_19 AC 217 ms
24,192 KB
testcase_20 AC 223 ms
24,064 KB
testcase_21 AC 220 ms
24,064 KB
testcase_22 AC 689 ms
48,512 KB
testcase_23 AC 690 ms
48,512 KB
testcase_24 AC 685 ms
48,384 KB
testcase_25 AC 697 ms
48,384 KB
testcase_26 AC 709 ms
48,384 KB
testcase_27 AC 430 ms
43,264 KB
testcase_28 AC 432 ms
43,648 KB
testcase_29 AC 419 ms
43,392 KB
testcase_30 AC 428 ms
43,264 KB
testcase_31 AC 417 ms
43,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    y = int(input())
    G[a].append((b, y))
    G[b].append((a, y))

X = [-1] * N
for i in range(N):
    if X[i] != -1:
        continue
    X[i] = 0
    q = [i]
    while q:
        s = q.pop()
        for t, y in G[s]:
            if X[t] == -1:
                X[t] = y ^ X[s]
                q.append(t)
                continue
            if X[s] ^ X[t] != y:
                print(-1)
                exit()

print(*X, sep="\n")
0