結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230
提出日時 2021-03-12 21:47:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 98,256 KB
最終ジャッジ日時 2024-10-14 12:06:05
合計ジャッジ時間 5,516 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
e = [[] for i in range(n)]
count = [0]*n
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    count[a] += 1
    count[b] += 1
    e[a].append(b)
    e[b].append(a)

cand = []
for i in range(n):
    if count[i] == 1:
        cand.append(i)

ind = cand[0]
dis = [10**10]*n
dis[ind] = 0

q = deque([ind])
while q:
    now = q.popleft()
    for nex in e[now]:
        if dis[nex] > dis[now]+1:
            dis[nex] = dis[now]+1
            q.append(nex)
num = dis[cand[1]]
for i in cand[2:]:
    if num != dis[i]:
        print("No")
        exit()
print("Yes")
0