結果

問題 No.1424 Ultrapalindrome
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-30 15:19:47
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 724 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 849,312 KB
最終ジャッジ日時 2023-09-02 01:39:08
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,880 KB
testcase_01 AC 88 ms
71,848 KB
testcase_02 AC 83 ms
71,620 KB
testcase_03 AC 85 ms
71,716 KB
testcase_04 AC 84 ms
71,476 KB
testcase_05 AC 86 ms
71,632 KB
testcase_06 AC 87 ms
71,632 KB
testcase_07 AC 85 ms
71,856 KB
testcase_08 AC 86 ms
71,416 KB
testcase_09 AC 185 ms
87,836 KB
testcase_10 AC 183 ms
87,884 KB
testcase_11 AC 165 ms
84,520 KB
testcase_12 AC 173 ms
85,708 KB
testcase_13 AC 130 ms
80,396 KB
testcase_14 AC 165 ms
84,732 KB
testcase_15 AC 89 ms
71,736 KB
testcase_16 AC 155 ms
83,976 KB
testcase_17 AC 161 ms
84,664 KB
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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