結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-18 15:29:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 613 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2024-04-28 05:48:23
合計ジャッジ時間 8,808 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 30 ms
10,624 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 29 ms
10,624 KB
testcase_05 AC 30 ms
10,496 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,624 KB
testcase_08 AC 30 ms
10,624 KB
testcase_09 AC 406 ms
23,680 KB
testcase_10 AC 413 ms
23,680 KB
testcase_11 AC 287 ms
19,712 KB
testcase_12 AC 391 ms
22,784 KB
testcase_13 AC 125 ms
14,336 KB
testcase_14 AC 315 ms
20,736 KB
testcase_15 AC 32 ms
10,496 KB
testcase_16 AC 254 ms
18,560 KB
testcase_17 AC 304 ms
20,096 KB
testcase_18 AC 224 ms
17,024 KB
testcase_19 AC 346 ms
20,096 KB
testcase_20 AC 99 ms
12,928 KB
testcase_21 RE -
testcase_22 AC 182 ms
15,488 KB
testcase_23 AC 60 ms
11,904 KB
testcase_24 AC 94 ms
12,800 KB
testcase_25 AC 90 ms
12,800 KB
testcase_26 AC 396 ms
22,272 KB
testcase_27 AC 513 ms
27,520 KB
testcase_28 AC 427 ms
27,008 KB
testcase_29 RE -
testcase_30 AC 444 ms
24,832 KB
testcase_31 AC 457 ms
27,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

leaf = set()
def dfs(cv, pv, G, d):
    is_leaf = True
    for nv in G[cv]:
        if nv == pv: continue
        dfs(nv, cv, G, d + 1)
        is_leaf = False
    
    if is_leaf: leaf.add(d)

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

deg3 = 0
cv = -1
for i in range(n):
    if 3 <= len(G[i]):
        deg3 += 1
        cv = i

if deg3 >= 2:
    print("No")
    exit()

if deg3 == 0:
    print("Yes")
    exit()

dfs(cv, -1, G, 0)

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