結果

問題 No.1424 Ultrapalindrome
ユーザー anagohirameanagohirame
提出日時 2021-03-12 22:03:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,040 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 36,736 KB
最終ジャッジ日時 2024-04-22 13:00:57
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 WA -
testcase_06 AC 30 ms
10,880 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 190 ms
20,864 KB
testcase_12 AC 250 ms
24,320 KB
testcase_13 AC 87 ms
14,720 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 167 ms
19,584 KB
testcase_17 AC 195 ms
21,376 KB
testcase_18 AC 193 ms
18,816 KB
testcase_19 AC 277 ms
21,760 KB
testcase_20 AC 82 ms
13,440 KB
testcase_21 AC 231 ms
20,172 KB
testcase_22 AC 150 ms
16,384 KB
testcase_23 AC 57 ms
12,672 KB
testcase_24 AC 82 ms
13,440 KB
testcase_25 AC 76 ms
12,928 KB
testcase_26 AC 345 ms
23,552 KB
testcase_27 WA -
testcase_28 AC 345 ms
31,360 KB
testcase_29 WA -
testcase_30 AC 374 ms
33,536 KB
testcase_31 AC 418 ms
36,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
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]) 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:
	print("Yes")
0