結果

問題 No.1424 Ultrapalindrome
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-30 15:47:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 104,640 KB
最終ジャッジ日時 2023-09-02 01:39:56
合計ジャッジ時間 7,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,888 KB
testcase_01 AC 92 ms
71,768 KB
testcase_02 AC 92 ms
71,600 KB
testcase_03 AC 91 ms
71,404 KB
testcase_04 AC 92 ms
71,600 KB
testcase_05 AC 92 ms
71,736 KB
testcase_06 AC 93 ms
71,572 KB
testcase_07 AC 93 ms
71,808 KB
testcase_08 AC 91 ms
71,604 KB
testcase_09 AC 216 ms
87,796 KB
testcase_10 AC 217 ms
87,720 KB
testcase_11 AC 183 ms
84,252 KB
testcase_12 AC 203 ms
85,516 KB
testcase_13 AC 146 ms
80,244 KB
testcase_14 AC 191 ms
84,800 KB
testcase_15 AC 92 ms
71,404 KB
testcase_16 AC 177 ms
84,104 KB
testcase_17 AC 188 ms
84,476 KB
testcase_18 AC 281 ms
101,264 KB
testcase_19 AC 365 ms
104,640 KB
testcase_20 AC 171 ms
81,020 KB
testcase_21 AC 245 ms
86,984 KB
testcase_22 AC 214 ms
85,192 KB
testcase_23 AC 128 ms
78,284 KB
testcase_24 AC 165 ms
81,336 KB
testcase_25 AC 167 ms
81,216 KB
testcase_26 AC 407 ms
102,980 KB
testcase_27 AC 239 ms
90,500 KB
testcase_28 AC 182 ms
88,396 KB
testcase_29 AC 215 ms
91,356 KB
testcase_30 AC 208 ms
92,136 KB
testcase_31 AC 210 ms
91,720 KB
権限があれば一括ダウンロードができます

ソースコード

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()
    cnt=0
    for i in range(n):
        if len(g[i])==1:
            q.append((i,-1,0))
            cnt+=1
            if cnt>10:
                break
    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