結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 箱星箱星
提出日時 2020-12-30 18:41:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 787 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 35,200 KB
最終ジャッジ日時 2024-04-22 16:54:46
合計ジャッジ時間 10,055 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,136 KB
testcase_01 AC 32 ms
11,136 KB
testcase_02 AC 33 ms
11,008 KB
testcase_03 AC 33 ms
11,008 KB
testcase_04 AC 34 ms
11,008 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 32 ms
11,136 KB
testcase_08 AC 33 ms
11,008 KB
testcase_09 AC 363 ms
24,704 KB
testcase_10 AC 357 ms
24,704 KB
testcase_11 AC 253 ms
20,736 KB
testcase_12 AC 344 ms
23,936 KB
testcase_13 AC 115 ms
14,592 KB
testcase_14 AC 279 ms
21,632 KB
testcase_15 AC 34 ms
11,008 KB
testcase_16 AC 225 ms
19,456 KB
testcase_17 AC 270 ms
21,120 KB
testcase_18 AC 348 ms
18,304 KB
testcase_19 AC 517 ms
20,864 KB
testcase_20 AC 146 ms
13,568 KB
testcase_21 AC 400 ms
18,944 KB
testcase_22 AC 267 ms
16,000 KB
testcase_23 AC 86 ms
12,800 KB
testcase_24 AC 138 ms
13,056 KB
testcase_25 AC 123 ms
13,184 KB
testcase_26 AC 597 ms
22,656 KB
testcase_27 AC 460 ms
28,032 KB
testcase_28 AC 397 ms
27,648 KB
testcase_29 AC 780 ms
27,520 KB
testcase_30 AC 778 ms
32,256 KB
testcase_31 AC 787 ms
35,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue

n = int(input())
adj = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
lst = []
for i in range(1, n + 1):
    if len(adj[i]) >= 3:
        lst.append(i)
if len(lst) >= 2:
    print("No")
elif len(lst) == 0:
    print("Yes")
else:
    lens = set([])
    que = queue.Queue()
    que.put((lst[0], -1, 0))
    while not que.empty():
        v, p, d = que.get()
        isleaf = True
        for w in adj[v]:
            if w != p:
                isleaf = False
                que.put((w, v, d + 1))
        if isleaf:
            lens.add(d)
    if len(lens) == 1:
        print("Yes")
    else:
        print("No")
0