結果

問題 No.1424 Ultrapalindrome
ユーザー rodea
提出日時 2021-03-17 18:51:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,800 KB
最終ジャッジ日時 2024-11-15 11:36:06
合計ジャッジ時間 9,482 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 3 RE * 4
権限があれば一括ダウンロードができます

ソースコード

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