結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-18 15:36:44
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 613 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 94,904 KB
最終ジャッジ日時 2023-08-10 12:37:29
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,224 KB
testcase_01 AC 70 ms
71,140 KB
testcase_02 AC 68 ms
71,512 KB
testcase_03 AC 71 ms
71,232 KB
testcase_04 AC 68 ms
71,004 KB
testcase_05 AC 70 ms
71,452 KB
testcase_06 AC 70 ms
71,320 KB
testcase_07 AC 69 ms
71,452 KB
testcase_08 AC 69 ms
71,352 KB
testcase_09 AC 183 ms
85,408 KB
testcase_10 AC 187 ms
85,932 KB
testcase_11 AC 154 ms
82,556 KB
testcase_12 AC 177 ms
85,356 KB
testcase_13 AC 119 ms
78,852 KB
testcase_14 AC 161 ms
82,824 KB
testcase_15 AC 73 ms
71,136 KB
testcase_16 AC 148 ms
82,092 KB
testcase_17 AC 156 ms
82,956 KB
testcase_18 AC 164 ms
82,236 KB
testcase_19 AC 217 ms
84,604 KB
testcase_20 AC 140 ms
80,172 KB
testcase_21 RE -
testcase_22 AC 163 ms
81,996 KB
testcase_23 AC 106 ms
78,296 KB
testcase_24 AC 147 ms
92,556 KB
testcase_25 AC 137 ms
84,328 KB
testcase_26 AC 224 ms
86,388 KB
testcase_27 AC 211 ms
90,132 KB
testcase_28 AC 155 ms
86,072 KB
testcase_29 RE -
testcase_30 AC 182 ms
91,460 KB
testcase_31 AC 182 ms
91,336 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