結果

問題 No.1424 Ultrapalindrome
ユーザー KudeKude
提出日時 2021-03-12 21:42:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 29,568 KB
最終ジャッジ日時 2024-04-22 12:32:31
合計ジャッジ時間 8,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 26 ms
10,624 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 WA -
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 27 ms
10,752 KB
testcase_06 AC 26 ms
10,752 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 25 ms
10,496 KB
testcase_09 AC 369 ms
24,192 KB
testcase_10 AC 357 ms
24,320 KB
testcase_11 AC 257 ms
20,224 KB
testcase_12 AC 351 ms
23,296 KB
testcase_13 AC 113 ms
14,336 KB
testcase_14 AC 297 ms
21,376 KB
testcase_15 AC 28 ms
10,752 KB
testcase_16 AC 217 ms
19,200 KB
testcase_17 AC 263 ms
20,736 KB
testcase_18 AC 205 ms
17,664 KB
testcase_19 AC 318 ms
21,120 KB
testcase_20 AC 94 ms
13,440 KB
testcase_21 RE -
testcase_22 AC 166 ms
16,000 KB
testcase_23 AC 58 ms
12,032 KB
testcase_24 AC 88 ms
13,312 KB
testcase_25 AC 84 ms
13,056 KB
testcase_26 AC 368 ms
23,296 KB
testcase_27 AC 461 ms
28,288 KB
testcase_28 AC 411 ms
28,160 KB
testcase_29 RE -
testcase_30 AC 442 ms
26,240 KB
testcase_31 AC 460 ms
29,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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