結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 27 ms
10,880 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 198 ms
17,920 KB
testcase_19 AC 314 ms
21,376 KB
testcase_20 AC 90 ms
13,440 KB
testcase_21 AC 243 ms
20,352 KB
testcase_22 AC 163 ms
16,128 KB
testcase_23 AC 54 ms
12,160 KB
testcase_24 AC 86 ms
13,440 KB
testcase_25 AC 80 ms
12,800 KB
testcase_26 AC 367 ms
23,300 KB
testcase_27 RE -
testcase_28 AC 387 ms
28,032 KB
testcase_29 WA -
testcase_30 AC 453 ms
27,392 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')
    exi()

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