結果

問題 No.1424 Ultrapalindrome
ユーザー KudeKude
提出日時 2021-03-12 21:44:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 47,432 KB
最終ジャッジ日時 2023-08-04 18:57:52
合計ジャッジ時間 7,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,320 KB
testcase_01 AC 14 ms
8,328 KB
testcase_02 AC 15 ms
8,216 KB
testcase_03 AC 15 ms
8,264 KB
testcase_04 AC 15 ms
8,316 KB
testcase_05 AC 15 ms
8,264 KB
testcase_06 AC 14 ms
8,276 KB
testcase_07 AC 16 ms
8,224 KB
testcase_08 AC 15 ms
8,208 KB
testcase_09 AC 307 ms
21,860 KB
testcase_10 AC 304 ms
21,744 KB
testcase_11 AC 208 ms
17,852 KB
testcase_12 AC 283 ms
21,020 KB
testcase_13 AC 89 ms
11,720 KB
testcase_14 AC 242 ms
18,688 KB
testcase_15 AC 16 ms
8,252 KB
testcase_16 AC 189 ms
16,612 KB
testcase_17 AC 224 ms
18,324 KB
testcase_18 AC 169 ms
15,124 KB
testcase_19 AC 266 ms
18,432 KB
testcase_20 AC 73 ms
10,648 KB
testcase_21 AC 233 ms
18,216 KB
testcase_22 AC 138 ms
13,504 KB
testcase_23 AC 42 ms
9,380 KB
testcase_24 AC 72 ms
10,948 KB
testcase_25 AC 65 ms
10,548 KB
testcase_26 AC 305 ms
20,732 KB
testcase_27 AC 382 ms
25,944 KB
testcase_28 AC 329 ms
25,548 KB
testcase_29 AC 425 ms
47,432 KB
testcase_30 AC 378 ms
24,028 KB
testcase_31 AC 405 ms
27,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
if n <= 3:
    print('Yes')
    exit()
deg = [0] * n
to = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    deg[a] += 1
    deg[b] += 1
imx = max(range(n), key=lambda i: deg[i])
if deg[imx] == 2:
    print('Yes')
    exit()
if any(i != imx and deg[i] >= 3 for i in range(n)):
    print('No')
    exit()
depth = [0] * n
def dfs(u, p=-1):
    if p >= 0:
        depth[u] = depth[p] + 1
    for v in to[u]:
        if v == p:
            continue
        dfs(v, u)
dfs(imx)
d = -1
ok = True
for i in range(n):
    if deg[i] == 1:
        if d == -1:
            d = depth[i]
        elif d != depth[i]:
            ok = False
            break
ans = 'Yes' if ok else 'No'
print(ans)
0