結果

問題 No.1424 Ultrapalindrome
ユーザー DrDrpilot
提出日時 2022-01-30 15:19:47
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 724 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 852,224 KB
最終ジャッジ日時 2024-06-11 08:17:56
合計ジャッジ時間 5,723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 MLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n=int(input())
g=[[] for _ in range(n)]
in_num=[0]*n
for _ in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
cnt_3=0
for i in range(n):
    if len(g[i])>=3:
        cnt_3+=1
if cnt_3>=2:
    print('No')
elif cnt_3==0:
    print('Yes')
else:
    q=deque()
    for i in range(n):
        if len(g[i])==1:
            q.append((i,-1,0))
    D=set()
    while q:
        now,pre,d=q.popleft()
        for to in g[now]:
            if to==pre:
                continue
            if len(g[to])==1:
                D.add(d+1)
                continue
            q.append((to,now,d+1))
    if len(D)==1:
        print('Yes')
    else:
        print('No')
0