結果

問題 No.1424 Ultrapalindrome
ユーザー brthyyjp
提出日時 2021-03-12 22:29:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 618 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,084 KB
最終ジャッジ日時 2024-10-14 13:00:51
合計ジャッジ時間 7,509 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
from collections import deque
q = deque([])
for v in range(n):
    if len(g[v]) == 1:
        q.append(v)
while n > 2:
    l = len(q)
    n -= l
    for i in range(l):
        v = q.popleft()
        for u in g[v]:
            g[u].remove(v)
            if len(g[u]) == 1:
                q.append(u)
#print(list(q))
if len(q) == 1:
    print('Yes')
else:
    print('No')
0