結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 WA -
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 33 ms
10,752 KB
testcase_09 AC 402 ms
24,576 KB
testcase_10 AC 415 ms
24,576 KB
testcase_11 AC 290 ms
20,608 KB
testcase_12 AC 374 ms
23,808 KB
testcase_13 AC 123 ms
14,208 KB
testcase_14 AC 322 ms
21,376 KB
testcase_15 AC 31 ms
10,880 KB
testcase_16 AC 255 ms
19,200 KB
testcase_17 AC 298 ms
20,864 KB
testcase_18 AC 251 ms
17,920 KB
testcase_19 AC 373 ms
21,376 KB
testcase_20 AC 113 ms
13,440 KB
testcase_21 AC 303 ms
20,480 KB
testcase_22 AC 196 ms
16,256 KB
testcase_23 AC 64 ms
12,288 KB
testcase_24 AC 103 ms
13,440 KB
testcase_25 AC 93 ms
12,928 KB
testcase_26 AC 443 ms
23,428 KB
testcase_27 AC 504 ms
28,672 KB
testcase_28 AC 436 ms
28,160 KB
testcase_29 WA -
testcase_30 AC 499 ms
27,520 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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(root + 1, 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