結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-18 15:36:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 609 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 25,348 KB
最終ジャッジ日時 2023-08-10 12:37:06
合計ジャッジ時間 7,582 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
15,032 KB
testcase_01 AC 45 ms
14,940 KB
testcase_02 AC 48 ms
15,056 KB
testcase_03 AC 45 ms
15,016 KB
testcase_04 AC 45 ms
14,952 KB
testcase_05 AC 44 ms
14,872 KB
testcase_06 AC 45 ms
15,072 KB
testcase_07 AC 45 ms
14,928 KB
testcase_08 AC 47 ms
14,952 KB
testcase_09 AC 331 ms
22,784 KB
testcase_10 AC 331 ms
22,748 KB
testcase_11 AC 242 ms
20,332 KB
testcase_12 AC 304 ms
22,188 KB
testcase_13 AC 115 ms
17,252 KB
testcase_14 AC 258 ms
20,968 KB
testcase_15 AC 46 ms
15,000 KB
testcase_16 AC 219 ms
19,904 KB
testcase_17 AC 251 ms
20,736 KB
testcase_18 AC 188 ms
18,712 KB
testcase_19 AC 269 ms
20,596 KB
testcase_20 AC 98 ms
16,740 KB
testcase_21 RE -
testcase_22 AC 154 ms
18,044 KB
testcase_23 AC 70 ms
15,940 KB
testcase_24 AC 103 ms
16,744 KB
testcase_25 AC 97 ms
16,496 KB
testcase_26 AC 354 ms
21,664 KB
testcase_27 AC 433 ms
25,100 KB
testcase_28 AC 352 ms
24,556 KB
testcase_29 RE -
testcase_30 AC 358 ms
22,424 KB
testcase_31 AC 373 ms
25,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n = int(input())
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, 0)

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