結果

問題 No.1420 国勢調査 (Easy)
ユーザー convexineqconvexineq
提出日時 2021-03-05 22:29:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,536 KB
最終ジャッジ日時 2024-04-16 10:14:35
合計ジャッジ時間 10,998 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,712 KB
testcase_01 AC 40 ms
52,096 KB
testcase_02 AC 288 ms
87,680 KB
testcase_03 AC 279 ms
86,400 KB
testcase_04 AC 285 ms
86,912 KB
testcase_05 AC 281 ms
86,656 KB
testcase_06 AC 286 ms
88,064 KB
testcase_07 AC 288 ms
87,680 KB
testcase_08 AC 281 ms
87,808 KB
testcase_09 AC 288 ms
88,064 KB
testcase_10 AC 270 ms
86,400 KB
testcase_11 AC 272 ms
86,656 KB
testcase_12 AC 159 ms
84,096 KB
testcase_13 AC 172 ms
86,528 KB
testcase_14 AC 157 ms
84,352 KB
testcase_15 AC 172 ms
86,360 KB
testcase_16 AC 176 ms
86,272 KB
testcase_17 AC 173 ms
86,400 KB
testcase_18 AC 171 ms
86,332 KB
testcase_19 AC 172 ms
86,632 KB
testcase_20 AC 171 ms
86,656 KB
testcase_21 AC 175 ms
86,480 KB
testcase_22 AC 390 ms
97,152 KB
testcase_23 AC 389 ms
97,024 KB
testcase_24 AC 372 ms
97,024 KB
testcase_25 AC 390 ms
97,536 KB
testcase_26 AC 393 ms
97,536 KB
testcase_27 AC 371 ms
93,056 KB
testcase_28 AC 376 ms
93,824 KB
testcase_29 AC 375 ms
93,184 KB
testcase_30 AC 375 ms
93,184 KB
testcase_31 AC 379 ms
93,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    l,r = map(int,input().split())
    y = int(input())
    g[l-1].append((r-1,y))
    g[r-1].append((l-1,y))

res = [-1]*n
ok = 1
for i in range(n):
    if res[i] == -1:
        res[i] = 0
        st = [i]
        while st:
            v = st.pop()
            for c,d in g[v]:
                if res[c] == -1:
                    res[c] = d ^ res[v]
                    st.append(c)
                else:
                    if res[c] != d ^ res[v]:
                        ok = 0

if ok:
    print(*res,sep="\n")
else:
    print(-1)
0