結果

問題 No.1424 Ultrapalindrome
ユーザー ああいいああいい
提出日時 2022-05-18 09:57:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 97,228 KB
最終ジャッジ日時 2023-10-14 16:22:22
合計ジャッジ時間 11,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 63 ms
71,332 KB
testcase_02 AC 64 ms
71,104 KB
testcase_03 AC 63 ms
71,172 KB
testcase_04 AC 63 ms
71,324 KB
testcase_05 AC 63 ms
71,212 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 62 ms
71,260 KB
testcase_09 AC 171 ms
91,028 KB
testcase_10 AC 161 ms
91,012 KB
testcase_11 AC 144 ms
85,912 KB
testcase_12 AC 164 ms
90,600 KB
testcase_13 AC 112 ms
79,348 KB
testcase_14 AC 150 ms
86,640 KB
testcase_15 AC 68 ms
71,416 KB
testcase_16 AC 135 ms
84,872 KB
testcase_17 AC 148 ms
86,460 KB
testcase_18 AC 355 ms
84,188 KB
testcase_19 AC 156 ms
84,652 KB
testcase_20 AC 110 ms
78,780 KB
testcase_21 AC 135 ms
83,332 KB
testcase_22 AC 119 ms
80,192 KB
testcase_23 AC 175 ms
78,448 KB
testcase_24 AC 105 ms
78,652 KB
testcase_25 AC 107 ms
78,420 KB
testcase_26 AC 166 ms
87,896 KB
testcase_27 AC 193 ms
97,228 KB
testcase_28 AC 146 ms
89,272 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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(a)
    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')
0