結果

問題 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
コンパイル時間 486 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 25,488 KB
最終ジャッジ日時 2023-08-10 12:31:52
合計ジャッジ時間 9,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,908 KB
testcase_01 AC 15 ms
7,792 KB
testcase_02 AC 16 ms
8,192 KB
testcase_03 AC 16 ms
8,340 KB
testcase_04 AC 16 ms
8,304 KB
testcase_05 AC 16 ms
8,148 KB
testcase_06 AC 16 ms
7,836 KB
testcase_07 AC 16 ms
7,868 KB
testcase_08 AC 16 ms
8,196 KB
testcase_09 AC 335 ms
21,096 KB
testcase_10 AC 324 ms
21,052 KB
testcase_11 AC 227 ms
17,388 KB
testcase_12 AC 306 ms
20,464 KB
testcase_13 AC 91 ms
11,660 KB
testcase_14 AC 254 ms
18,148 KB
testcase_15 AC 16 ms
8,316 KB
testcase_16 AC 198 ms
16,080 KB
testcase_17 AC 238 ms
17,920 KB
testcase_18 AC 171 ms
14,720 KB
testcase_19 AC 260 ms
17,728 KB
testcase_20 AC 72 ms
10,556 KB
testcase_21 RE -
testcase_22 AC 136 ms
13,244 KB
testcase_23 AC 40 ms
9,424 KB
testcase_24 AC 68 ms
10,504 KB
testcase_25 AC 63 ms
10,244 KB
testcase_26 AC 319 ms
19,672 KB
testcase_27 AC 412 ms
25,220 KB
testcase_28 AC 347 ms
24,796 KB
testcase_29 RE -
testcase_30 AC 360 ms
22,340 KB
testcase_31 AC 377 ms
25,488 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