結果
問題 | No.1424 Ultrapalindrome |
ユーザー | nephrologist |
提出日時 | 2021-03-12 22:46:25 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,023 bytes |
コンパイル時間 | 198 ms |
コンパイル使用メモリ | 81,872 KB |
実行使用メモリ | 118,140 KB |
最終ジャッジ日時 | 2024-10-14 13:19:45 |
合計ジャッジ時間 | 5,465 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,968 KB |
testcase_01 | AC | 43 ms
54,092 KB |
testcase_02 | AC | 43 ms
55,600 KB |
testcase_03 | AC | 43 ms
55,268 KB |
testcase_04 | AC | 43 ms
55,368 KB |
testcase_05 | WA | - |
testcase_06 | AC | 43 ms
55,712 KB |
testcase_07 | AC | 42 ms
54,624 KB |
testcase_08 | WA | - |
testcase_09 | AC | 239 ms
95,036 KB |
testcase_10 | AC | 232 ms
95,224 KB |
testcase_11 | AC | 185 ms
88,696 KB |
testcase_12 | AC | 216 ms
94,376 KB |
testcase_13 | AC | 117 ms
80,936 KB |
testcase_14 | AC | 192 ms
90,724 KB |
testcase_15 | AC | 44 ms
55,264 KB |
testcase_16 | AC | 171 ms
88,108 KB |
testcase_17 | AC | 186 ms
89,056 KB |
testcase_18 | AC | 153 ms
86,824 KB |
testcase_19 | AC | 186 ms
88,952 KB |
testcase_20 | AC | 105 ms
78,972 KB |
testcase_21 | AC | 169 ms
86,632 KB |
testcase_22 | AC | 129 ms
82,916 KB |
testcase_23 | AC | 82 ms
78,116 KB |
testcase_24 | AC | 100 ms
78,700 KB |
testcase_25 | AC | 99 ms
78,896 KB |
testcase_26 | AC | 208 ms
92,712 KB |
testcase_27 | WA | - |
testcase_28 | AC | 135 ms
106,828 KB |
testcase_29 | WA | - |
testcase_30 | AC | 155 ms
117,404 KB |
testcase_31 | AC | 159 ms
118,140 KB |
ソースコード
import sys from collections import deque input = sys.stdin.buffer.readline n = int(input()) graph = [[] for _ in range(n)] deg1 = [0] * n deg2 = [0] * n for _ in range(n - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) deg1[a] += 1 deg1[b] += 1 kouho = deque() haji = [] dist1 = [-1] * n done = [0] * n for i in range(n): if deg1[i] == 1: haji.append(i) def ok(): print("Yes") exit() def ng(): print("No") exit() # graph and n is necessary def dfs(start): par = [-1] * n depth = [-1] * n size = [0] * n stack = [] euler = [] stack.append(~start) stack.append(start) depth[start] = 0 while stack: v = stack.pop() if v >= 0: d = depth[v] euler.append(v) for u in graph[v]: if par[v] == u: continue par[u] = v depth[u] = d + 1 stack.append(~u) stack.append(u) else: a = ~v size[a] = 1 for u in graph[a]: if u == par[a]: continue size[a] += size[u] return par, size, euler par, size, euler = dfs(0) grav = [] for v in euler: flag = 1 if n - size[v] >= n // 2: continue for u in graph[v]: if u == par[v]: continue if size[u] >= n // 2: flag = 0 if flag: grav.append(v) assert len(grav) <= 2 # deque is necessary. # n, graph, start is necessary def BFS(grav): dist = [-1] * n que = deque() for v in grav: que.append(v) dist[v] = 0 while que: v = que.popleft() d = dist[v] for u in graph[v]: if dist[u] == -1: dist[u] = d + 1 que.append(u) return dist dist = BFS(grav) temp = dist[haji[0]] for v in haji: if dist[v] != temp: ng() ok()