結果

問題 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
コンパイル時間 369 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-04-28 05:53:23
合計ジャッジ時間 9,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
17,792 KB
testcase_01 AC 71 ms
17,920 KB
testcase_02 AC 68 ms
17,664 KB
testcase_03 AC 68 ms
17,792 KB
testcase_04 AC 70 ms
17,664 KB
testcase_05 AC 70 ms
17,664 KB
testcase_06 AC 70 ms
17,920 KB
testcase_07 AC 69 ms
17,792 KB
testcase_08 AC 70 ms
17,792 KB
testcase_09 AC 432 ms
25,088 KB
testcase_10 AC 431 ms
25,088 KB
testcase_11 AC 322 ms
23,168 KB
testcase_12 AC 414 ms
24,832 KB
testcase_13 AC 157 ms
19,712 KB
testcase_14 AC 339 ms
23,424 KB
testcase_15 AC 70 ms
17,664 KB
testcase_16 AC 287 ms
22,528 KB
testcase_17 AC 325 ms
23,168 KB
testcase_18 AC 258 ms
21,248 KB
testcase_19 AC 366 ms
23,296 KB
testcase_20 AC 137 ms
19,072 KB
testcase_21 RE -
testcase_22 AC 217 ms
20,736 KB
testcase_23 AC 99 ms
18,304 KB
testcase_24 AC 134 ms
19,072 KB
testcase_25 AC 130 ms
18,816 KB
testcase_26 AC 419 ms
24,320 KB
testcase_27 AC 518 ms
27,520 KB
testcase_28 AC 429 ms
27,008 KB
testcase_29 RE -
testcase_30 AC 448 ms
24,704 KB
testcase_31 AC 451 ms
28,032 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