結果

問題 No.1424 Ultrapalindrome
ユーザー ああいいああいい
提出日時 2022-05-18 10:01:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 908 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 114,792 KB
最終ジャッジ日時 2023-10-14 16:26:37
合計ジャッジ時間 6,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,164 KB
testcase_01 AC 69 ms
71,484 KB
testcase_02 AC 71 ms
71,448 KB
testcase_03 AC 70 ms
70,992 KB
testcase_04 AC 68 ms
71,232 KB
testcase_05 AC 69 ms
71,384 KB
testcase_06 AC 69 ms
71,168 KB
testcase_07 AC 70 ms
70,988 KB
testcase_08 AC 68 ms
71,308 KB
testcase_09 AC 175 ms
91,084 KB
testcase_10 AC 170 ms
91,044 KB
testcase_11 AC 146 ms
85,776 KB
testcase_12 AC 164 ms
90,440 KB
testcase_13 AC 117 ms
79,412 KB
testcase_14 AC 155 ms
86,392 KB
testcase_15 AC 70 ms
71,316 KB
testcase_16 AC 141 ms
85,044 KB
testcase_17 AC 151 ms
86,544 KB
testcase_18 AC 153 ms
83,836 KB
testcase_19 AC 173 ms
85,468 KB
testcase_20 AC 122 ms
78,844 KB
testcase_21 AC 158 ms
83,376 KB
testcase_22 AC 138 ms
81,632 KB
testcase_23 AC 109 ms
78,300 KB
testcase_24 AC 120 ms
78,808 KB
testcase_25 AC 122 ms
78,972 KB
testcase_26 AC 187 ms
87,604 KB
testcase_27 AC 206 ms
97,116 KB
testcase_28 AC 155 ms
89,052 KB
testcase_29 AC 166 ms
89,832 KB
testcase_30 AC 189 ms
113,292 KB
testcase_31 AC 193 ms
114,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for _ in range(N)]
Gnum = [0] * N
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    Gnum[a] += 1
    Gnum[b] += 1

ha = 0
has = set()
for j in range(N):
    i = Gnum[j]
    if i == 1:
        ha += 1
        has.add(j)
import sys
if ha == 2:
    print('Yes')
    exit()
count = 0
center = -1
for j in range(N):
    i = Gnum[j]
    if 2 < i < ha:
        print('No')
        exit()
    if i == ha:
        count += 1
        center = j

if count != 1:
    print('No')
    exit()
dist = [0] * N
stack = [(center,-1)]
while stack:
    now,parent = stack.pop()
    for v in G[now]:
        if v == parent:continue
        dist[v] = dist[now] + 1
        stack.append((v,now))
s = set()
for v in has:
    s.add(dist[v])
if len(s) == 1:
    print('Yes')
else:
    print('No')
"""
print(s)
print(dist)
print(center)
"""
0