結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-17 19:41:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 635 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 26,368 KB
最終ジャッジ日時 2023-08-09 17:18:50
合計ジャッジ時間 12,619 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,876 KB
testcase_01 AC 15 ms
7,776 KB
testcase_02 AC 15 ms
7,940 KB
testcase_03 AC 15 ms
7,820 KB
testcase_04 AC 16 ms
7,816 KB
testcase_05 AC 15 ms
7,820 KB
testcase_06 AC 15 ms
7,768 KB
testcase_07 AC 15 ms
7,744 KB
testcase_08 AC 14 ms
7,772 KB
testcase_09 AC 786 ms
21,868 KB
testcase_10 AC 798 ms
21,552 KB
testcase_11 AC 429 ms
17,840 KB
testcase_12 AC 713 ms
21,052 KB
testcase_13 AC 150 ms
11,928 KB
testcase_14 AC 557 ms
18,632 KB
testcase_15 AC 17 ms
7,780 KB
testcase_16 AC 393 ms
16,420 KB
testcase_17 AC 505 ms
18,212 KB
testcase_18 AC 292 ms
14,892 KB
testcase_19 AC 557 ms
18,152 KB
testcase_20 AC 106 ms
10,568 KB
testcase_21 RE -
testcase_22 AC 216 ms
13,296 KB
testcase_23 AC 55 ms
9,340 KB
testcase_24 RE -
testcase_25 AC 114 ms
10,516 KB
testcase_26 AC 723 ms
20,248 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 575 ms
23,320 KB
testcase_31 AC 575 ms
26,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

leaf = set()

def dfs(cv, pv, G, depth):
    is_leaf = True
    for nv in G[cv]:
        if nv == pv:
            continue
        dfs(nv, cv, G, depth + 1)
        is_leaf = False

    if is_leaf:
        leaf.add(depth)

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

root = []
for i in range(n):
    if deg[i] == 1 and len(root) <= 10:
        root.append(i)

for i in root:
    dfs(i, -1, G, 0)

if len(leaf) == 1:
    print("Yes")
else:
    print("No")
0