結果
問題 | No.1420 国勢調査 (Easy) |
ユーザー | c-yan |
提出日時 | 2021-03-06 11:26:54 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,044 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 11,088 KB |
実行使用メモリ | 41,980 KB |
最終ジャッジ日時 | 2023-07-29 18:10:49 |
合計ジャッジ時間 | 12,924 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
8,748 KB |
testcase_01 | AC | 18 ms
8,736 KB |
testcase_02 | AC | 406 ms
28,112 KB |
testcase_03 | AC | 408 ms
28,448 KB |
testcase_04 | AC | 410 ms
28,036 KB |
testcase_05 | AC | 399 ms
28,104 KB |
testcase_06 | AC | 425 ms
28,052 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 37 ms
12,644 KB |
testcase_13 | RE | - |
testcase_14 | AC | 46 ms
14,148 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 192 ms
30,332 KB |
testcase_28 | RE | - |
testcase_29 | AC | 102 ms
21,552 KB |
testcase_30 | AC | 293 ms
34,908 KB |
testcase_31 | AC | 282 ms
34,404 KB |
ソースコード
from sys import setrecursionlimit, stdin from collections import deque def find(parent, i): t = parent[i] if t < 0: return i t = find(parent, t) parent[i] = t return t def unite(parent, i, j): i = find(parent, i) j = find(parent, j) if i == j: return parent[j] += parent[i] parent[i] = j readline = stdin.readline setrecursionlimit(10 ** 6) N, M = map(int, readline().split()) parent = [-1] * N d = {} for _ in range(M): A, B = map(lambda x: int(x) - 1, readline().split()) Y = int(readline()) if A in d and B in d[A]: if d[A][B] != Y: print(-1) exit() d.setdefault(A, {}) d.setdefault(B, {}) d[A][B] = Y d[B][A] = Y unite(parent, A, B) result = [-1] * N q = deque(i for i in range(N) if parent[i] < 0) for i in q: result[i] = 0 while q: a = q.popleft() for b in d[a]: if result[b] != -1: continue result[b] = result[a] ^ d[a][b] q.append(b) print(*result, sep='\n')