結果

問題 No.1420 国勢調査 (Easy)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-02-13 20:18:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,196 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 56,652 KB
最終ジャッジ日時 2023-09-11 15:40:02
合計ジャッジ時間 22,120 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,676 KB
testcase_01 AC 19 ms
8,612 KB
testcase_02 AC 947 ms
45,924 KB
testcase_03 AC 940 ms
45,912 KB
testcase_04 AC 948 ms
45,836 KB
testcase_05 AC 947 ms
45,896 KB
testcase_06 AC 955 ms
45,836 KB
testcase_07 AC 757 ms
45,784 KB
testcase_08 AC 783 ms
45,784 KB
testcase_09 AC 808 ms
45,868 KB
testcase_10 AC 763 ms
45,952 KB
testcase_11 AC 781 ms
45,836 KB
testcase_12 AC 92 ms
18,064 KB
testcase_13 AC 232 ms
22,616 KB
testcase_14 AC 112 ms
18,320 KB
testcase_15 AC 228 ms
22,660 KB
testcase_16 AC 230 ms
22,616 KB
testcase_17 AC 225 ms
22,556 KB
testcase_18 AC 229 ms
22,568 KB
testcase_19 AC 227 ms
22,620 KB
testcase_20 AC 225 ms
22,604 KB
testcase_21 AC 225 ms
22,556 KB
testcase_22 AC 1,192 ms
56,572 KB
testcase_23 AC 1,196 ms
56,616 KB
testcase_24 AC 1,185 ms
56,652 KB
testcase_25 AC 1,188 ms
56,596 KB
testcase_26 AC 1,184 ms
56,580 KB
testcase_27 AC 406 ms
34,572 KB
testcase_28 AC 799 ms
52,828 KB
testcase_29 AC 230 ms
25,220 KB
testcase_30 AC 570 ms
38,380 KB
testcase_31 AC 551 ms
37,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
e = [[] for _ in range(N)]
from collections import defaultdict
d = defaultdict(lambda:-1)
for _ in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    y = int(input())
    if d[(a,b)] != -1:
        if d[(a,b)] != y:
            print(-1)
            exit()
    d[(a,b)] = y
    d[(b,a)] = y
    e[a].append(b)
    e[b].append(a)
    
X = [-1]*N
from collections import deque
v = deque()
for i in range(N):
    if X[i] != -1:
        continue
    X[i] = 0
    v.append(i)
    
    while v:
        x = v.popleft()
        
        for ix in e[x]:
            if X[ix] == -1:
                X[ix] = X[x]^d[(x,ix)]
                v.append(ix)
            if X[ix] != -1:
                if X[ix] != X[x]^d[(x,ix)]:
                    print(-1)
                    exit()
print(*X,sep='\n')
0