結果

問題 No.1424 Ultrapalindrome
ユーザー c-yanc-yan
提出日時 2021-03-13 19:27:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 32,000 KB
最終ジャッジ日時 2024-04-23 09:47:52
合計ジャッジ時間 7,747 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 27 ms
10,880 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 25 ms
10,624 KB
testcase_07 AC 25 ms
10,880 KB
testcase_08 AC 25 ms
10,752 KB
testcase_09 AC 337 ms
24,448 KB
testcase_10 AC 336 ms
24,448 KB
testcase_11 AC 250 ms
20,352 KB
testcase_12 AC 325 ms
23,680 KB
testcase_13 AC 112 ms
14,336 KB
testcase_14 AC 266 ms
21,376 KB
testcase_15 AC 29 ms
10,880 KB
testcase_16 AC 220 ms
19,200 KB
testcase_17 AC 256 ms
20,736 KB
testcase_18 AC 216 ms
17,920 KB
testcase_19 AC 331 ms
21,376 KB
testcase_20 AC 96 ms
13,440 KB
testcase_21 AC 259 ms
20,480 KB
testcase_22 AC 173 ms
16,256 KB
testcase_23 AC 58 ms
12,160 KB
testcase_24 AC 89 ms
13,440 KB
testcase_25 AC 87 ms
12,800 KB
testcase_26 AC 378 ms
23,308 KB
testcase_27 AC 454 ms
28,672 KB
testcase_28 AC 409 ms
28,032 KB
testcase_29 AC 474 ms
32,000 KB
testcase_30 AC 457 ms
27,392 KB
testcase_31 AC 476 ms
30,336 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()

for i in range(N):
    if len(links[i]) < 3:
        continue
    break

root = i
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)

for i in range(N):
    if len(links[i]) != 1:
        continue
    a = d[i]
    break

for i in range(i + 1, N):
    if len(links[i]) != 1:
        continue
    if d[i] == a:
        continue
    print('No')
    break
else:
    print('Yes')
0