結果
問題 | No.1424 Ultrapalindrome |
ユーザー | anagohirame |
提出日時 | 2021-03-12 22:17:52 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,106 bytes |
コンパイル時間 | 324 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 36,608 KB |
最終ジャッジ日時 | 2024-04-22 13:19:13 |
合計ジャッジ時間 | 6,822 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
10,624 KB |
testcase_01 | AC | 29 ms
10,624 KB |
testcase_02 | AC | 29 ms
10,752 KB |
testcase_03 | AC | 27 ms
10,624 KB |
testcase_04 | AC | 27 ms
10,624 KB |
testcase_05 | AC | 26 ms
10,496 KB |
testcase_06 | AC | 27 ms
10,752 KB |
testcase_07 | WA | - |
testcase_08 | AC | 27 ms
10,752 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 160 ms
20,736 KB |
testcase_12 | AC | 205 ms
24,192 KB |
testcase_13 | AC | 73 ms
14,464 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 142 ms
19,328 KB |
testcase_17 | AC | 166 ms
21,248 KB |
testcase_18 | AC | 171 ms
18,688 KB |
testcase_19 | AC | 246 ms
21,504 KB |
testcase_20 | AC | 76 ms
13,184 KB |
testcase_21 | AC | 194 ms
20,076 KB |
testcase_22 | AC | 134 ms
16,256 KB |
testcase_23 | AC | 53 ms
12,288 KB |
testcase_24 | AC | 75 ms
13,440 KB |
testcase_25 | AC | 67 ms
12,928 KB |
testcase_26 | AC | 292 ms
23,296 KB |
testcase_27 | AC | 428 ms
32,640 KB |
testcase_28 | AC | 317 ms
31,104 KB |
testcase_29 | AC | 406 ms
31,872 KB |
testcase_30 | AC | 362 ms
33,536 KB |
testcase_31 | AC | 369 ms
36,608 KB |
ソースコード
import sys def input(): return sys.stdin.buffer.readline()[:-1] n = int(input()) adj = [[] for _ in range(n)] for _ in range(n-1): a, b = map(int, input().split()) adj[a-1].append(b-1) adj[b-1].append(a-1) for i in range(n): if len(adj[i]) == 1: leaf = i break depth = [1000000 for _ in range(n)] depth[leaf] = 0 st = [(leaf, -1)] while st: i, p = st.pop() if len(adj[i]) == 1 and i != leaf: other = i break for j in adj[i]: if j == p: continue else: depth[j] = depth[i] + 1 st.append((j, i)) if depth[other] % 2 == 1: print("Yes" if max(len(adj[i]) <= 2 for i in range(n)) else "No") sys.exit() for i in range(n): if depth[i] == depth[other] // 2: center = i assumed = depth[i] break depth = [1000000 for _ in range(n)] depth[center] = 0 st = [(center, -1)] while st: i, p = st.pop() if len(adj[i]) == 1 and depth[i] != assumed: print("No") break for j in adj[i]: if j == p: continue else: depth[j] = depth[i] + 1 st.append((j, i)) else: for i in range(n): if i != center and len(adj[i]) > 2: print("No") break else: print("Yes")