結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-17 18:51:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 26,272 KB
最終ジャッジ日時 2023-08-09 15:29:23
合計ジャッジ時間 10,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,864 KB
testcase_01 AC 15 ms
7,896 KB
testcase_02 AC 15 ms
7,848 KB
testcase_03 AC 15 ms
7,812 KB
testcase_04 AC 15 ms
7,920 KB
testcase_05 AC 16 ms
7,900 KB
testcase_06 AC 16 ms
7,900 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 383 ms
21,640 KB
testcase_10 AC 391 ms
21,684 KB
testcase_11 AC 261 ms
17,664 KB
testcase_12 AC 360 ms
20,844 KB
testcase_13 AC 102 ms
11,788 KB
testcase_14 AC 293 ms
18,652 KB
testcase_15 AC 16 ms
7,804 KB
testcase_16 AC 225 ms
16,208 KB
testcase_17 AC 273 ms
18,280 KB
testcase_18 AC 177 ms
14,956 KB
testcase_19 AC 277 ms
18,200 KB
testcase_20 AC 74 ms
10,596 KB
testcase_21 RE -
testcase_22 AC 137 ms
13,436 KB
testcase_23 AC 41 ms
9,500 KB
testcase_24 RE -
testcase_25 AC 65 ms
10,280 KB
testcase_26 AC 349 ms
20,232 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 365 ms
23,120 KB
testcase_31 AC 383 ms
26,272 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 = -1
for i in range(n):
    if deg[i] == 1:
        root = i
        break

dfs(root, -1, G, 0)

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