結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 tamatotamato
提出日時 2021-03-05 22:00:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 93,236 KB
最終ジャッジ日時 2024-04-16 09:29:13
合計ジャッジ時間 7,706 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,400 KB
testcase_01 AC 47 ms
54,144 KB
testcase_02 AC 179 ms
86,144 KB
testcase_03 AC 169 ms
85,900 KB
testcase_04 AC 167 ms
85,756 KB
testcase_05 AC 176 ms
86,016 KB
testcase_06 AC 168 ms
85,752 KB
testcase_07 AC 148 ms
85,376 KB
testcase_08 AC 139 ms
82,592 KB
testcase_09 AC 154 ms
85,684 KB
testcase_10 AC 150 ms
85,504 KB
testcase_11 AC 149 ms
85,484 KB
testcase_12 AC 90 ms
83,048 KB
testcase_13 AC 127 ms
83,968 KB
testcase_14 AC 85 ms
83,328 KB
testcase_15 AC 121 ms
83,536 KB
testcase_16 AC 124 ms
84,096 KB
testcase_17 AC 123 ms
83,712 KB
testcase_18 AC 123 ms
83,680 KB
testcase_19 AC 125 ms
83,516 KB
testcase_20 AC 121 ms
83,552 KB
testcase_21 AC 124 ms
83,712 KB
testcase_22 AC 265 ms
92,956 KB
testcase_23 AC 258 ms
93,236 KB
testcase_24 AC 270 ms
93,040 KB
testcase_25 AC 275 ms
93,208 KB
testcase_26 AC 267 ms
93,100 KB
testcase_27 AC 189 ms
92,472 KB
testcase_28 AC 190 ms
91,936 KB
testcase_29 AC 179 ms
92,212 KB
testcase_30 AC 190 ms
92,400 KB
testcase_31 AC 182 ms
92,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

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

    seen = [-1] * (N+1)
    for v0 in range(1, N+1):
        if seen[v0] != -1:
            continue
        seen[v0] = 0
        que = deque()
        que.append(v0)
        while que:
            v = que.popleft()
            for u, y in adj[v]:
                if seen[u] == -1:
                    que.append(u)
                    seen[u] = seen[v] ^ y
                else:
                    if seen[v] ^ seen[u] != y:
                        print(-1)
                        exit()
    for v in range(1, N+1):
        print(seen[v])


if __name__ == '__main__':
    main()
0