結果

問題 No.1420 国勢調査 (Easy)
ユーザー ygd.ygd.
提出日時 2021-03-05 22:49:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,132 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 58,112 KB
最終ジャッジ日時 2024-04-16 10:37:29
合計ジャッジ時間 23,487 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 879 ms
45,056 KB
testcase_03 AC 863 ms
45,056 KB
testcase_04 AC 863 ms
44,928 KB
testcase_05 AC 873 ms
45,056 KB
testcase_06 AC 865 ms
45,056 KB
testcase_07 AC 839 ms
45,556 KB
testcase_08 AC 811 ms
45,824 KB
testcase_09 AC 830 ms
44,928 KB
testcase_10 AC 826 ms
44,928 KB
testcase_11 AC 787 ms
44,672 KB
testcase_12 AC 159 ms
22,784 KB
testcase_13 AC 250 ms
25,728 KB
testcase_14 AC 158 ms
22,912 KB
testcase_15 AC 247 ms
25,728 KB
testcase_16 AC 245 ms
25,600 KB
testcase_17 AC 253 ms
25,728 KB
testcase_18 AC 253 ms
25,728 KB
testcase_19 AC 248 ms
25,856 KB
testcase_20 AC 248 ms
25,728 KB
testcase_21 AC 250 ms
25,728 KB
testcase_22 AC 1,129 ms
58,112 KB
testcase_23 AC 1,117 ms
58,112 KB
testcase_24 AC 1,126 ms
57,984 KB
testcase_25 AC 1,123 ms
57,984 KB
testcase_26 AC 1,132 ms
57,728 KB
testcase_27 AC 874 ms
51,584 KB
testcase_28 AC 880 ms
51,584 KB
testcase_29 AC 865 ms
51,712 KB
testcase_30 AC 860 ms
51,456 KB
testcase_31 AC 864 ms
51,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(500000)
N,M = map(int,input().split())
C = []
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))
    C.append((A,B,Y))

    
used = [0]*N
X = [-1]*N

def dfs(v,par=-1):
    for u,y in G[v]:
        if used[u] == 1:
            if X[v]^X[u] != y:
                print(-1);exit()
        else:
            X[u] = X[v]^y
            used[u] = 1
            dfs(u,v)

for i in range(N):
    if used[i] == 1: continue
    X[i] = 0
    dfs(i)

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