結果

問題 No.1424 Ultrapalindrome
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-30 15:10:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 777 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 27,556 KB
最終ジャッジ日時 2023-09-02 01:38:28
合計ジャッジ時間 9,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,520 KB
testcase_01 AC 17 ms
8,568 KB
testcase_02 AC 18 ms
8,520 KB
testcase_03 AC 18 ms
8,516 KB
testcase_04 AC 18 ms
8,620 KB
testcase_05 AC 18 ms
8,676 KB
testcase_06 AC 16 ms
8,544 KB
testcase_07 WA -
testcase_08 AC 18 ms
8,536 KB
testcase_09 AC 290 ms
22,168 KB
testcase_10 AC 284 ms
22,076 KB
testcase_11 AC 210 ms
18,028 KB
testcase_12 AC 271 ms
21,328 KB
testcase_13 AC 88 ms
12,172 KB
testcase_14 AC 234 ms
19,004 KB
testcase_15 AC 18 ms
8,608 KB
testcase_16 AC 188 ms
16,756 KB
testcase_17 AC 223 ms
18,496 KB
testcase_18 AC 177 ms
16,356 KB
testcase_19 AC 273 ms
19,068 KB
testcase_20 AC 77 ms
10,960 KB
testcase_21 AC 222 ms
16,864 KB
testcase_22 AC 139 ms
13,984 KB
testcase_23 AC 41 ms
9,768 KB
testcase_24 AC 70 ms
10,820 KB
testcase_25 AC 65 ms
10,696 KB
testcase_26 AC 336 ms
21,100 KB
testcase_27 AC 374 ms
26,180 KB
testcase_28 AC 335 ms
25,824 KB
testcase_29 WA -
testcase_30 AC 356 ms
24,316 KB
testcase_31 AC 377 ms
27,556 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()
    for i in range(n):
        if len(g[i])==1:
            q.append((i,0))
            break
    D=set()
    visit=[False]*n
    while q:
        now,d=q.popleft()
        visit[now]=True
        for to in g[now]:
            if visit[to]:
                continue
            if len(g[to])==1:
                D.add(d+1)
                continue
            q.append((to,d+1))
    if len(D)==1:
        print('Yes')
    else:
        print('No')
0