結果

問題 No.1424 Ultrapalindrome
ユーザー c-yanc-yan
提出日時 2021-03-13 19:33:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-04-23 09:52:52
合計ジャッジ時間 8,497 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,624 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 30 ms
10,624 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 32 ms
10,752 KB
testcase_09 AC 403 ms
24,320 KB
testcase_10 AC 411 ms
24,448 KB
testcase_11 AC 281 ms
20,352 KB
testcase_12 AC 384 ms
23,552 KB
testcase_13 AC 124 ms
14,464 KB
testcase_14 AC 320 ms
21,248 KB
testcase_15 AC 32 ms
10,624 KB
testcase_16 AC 249 ms
19,072 KB
testcase_17 AC 301 ms
20,608 KB
testcase_18 AC 254 ms
17,792 KB
testcase_19 AC 379 ms
21,120 KB
testcase_20 AC 115 ms
13,312 KB
testcase_21 AC 313 ms
20,352 KB
testcase_22 AC 208 ms
16,128 KB
testcase_23 AC 66 ms
12,160 KB
testcase_24 AC 105 ms
13,312 KB
testcase_25 AC 97 ms
12,800 KB
testcase_26 AC 453 ms
23,288 KB
testcase_27 AC 506 ms
28,544 KB
testcase_28 AC 435 ms
28,032 KB
testcase_29 AC 531 ms
31,872 KB
testcase_30 AC 517 ms
27,264 KB
testcase_31 AC 523 ms
30,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

links = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    links[a].append(b)
    links[b].append(a)

a = sorted((len(l) for l in links), reverse=True)
if a[0] <= 2:
    print('Yes')
    exit()
elif a[1] >= 3:
    print('No')
    exit()

root = [i for i in range(N) if len(links[i]) >= 3][0]
d = [-1] * N
d[root] = 0
q = [root]
while q:
    i = q.pop()
    for j in links[i]:
        if d[j] != -1:
            continue
        d[j] = d[i] + 1
        q.append(j)

a = [d[i] for i in range(N) if len(links[i]) == 1]
x = a[0]
if all(x == y for y in a):
    print('Yes')
else:
    print('No')
0