結果

問題 No.1424 Ultrapalindrome
ユーザー paruf4paruf4
提出日時 2021-03-13 14:03:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-23 06:08:13
合計ジャッジ時間 7,582 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 25 ms
10,880 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 342 ms
24,448 KB
testcase_10 AC 351 ms
24,576 KB
testcase_11 AC 248 ms
20,352 KB
testcase_12 AC 317 ms
23,680 KB
testcase_13 AC 107 ms
14,464 KB
testcase_14 AC 260 ms
21,376 KB
testcase_15 AC 30 ms
10,752 KB
testcase_16 AC 210 ms
18,944 KB
testcase_17 AC 256 ms
20,608 KB
testcase_18 AC 216 ms
17,792 KB
testcase_19 AC 304 ms
20,608 KB
testcase_20 AC 94 ms
13,056 KB
testcase_21 AC 247 ms
18,688 KB
testcase_22 AC 164 ms
15,744 KB
testcase_23 AC 59 ms
12,160 KB
testcase_24 AC 88 ms
13,056 KB
testcase_25 AC 84 ms
12,800 KB
testcase_26 AC 363 ms
22,400 KB
testcase_27 AC 421 ms
27,776 KB
testcase_28 AC 387 ms
27,392 KB
testcase_29 AC 451 ms
27,136 KB
testcase_30 AC 461 ms
32,000 KB
testcase_31 AC 474 ms
34,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
G = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

l = []
for i in range(n):
    if len(G[i]) >= 3:
        l.append(i)

if len(l) >= 2:
    print("No")
elif len(l) == 0:
    print("Yes")
else:
    s = set()
    q = deque()
    q.append((l[0],-1,0))
    while q:
        cur ,par ,dist = q.popleft()
        isleaf = True
        for nx in G[cur]:
            if nx != par:
                isleaf = False
                q.append((nx,cur,dist+1))
        if isleaf:
            s.add(dist)
    if len(s) == 1:
        print("Yes")
    else:
        print("No")
0