結果

問題 No.1424 Ultrapalindrome
ユーザー c-yanc-yan
提出日時 2021-03-12 23:10:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 680 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,232 KB
最終ジャッジ日時 2024-04-22 14:41:08
合計ジャッジ時間 9,193 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 30 ms
10,624 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 473 ms
24,192 KB
testcase_10 AC 479 ms
24,320 KB
testcase_11 AC 332 ms
20,480 KB
testcase_12 AC 446 ms
23,424 KB
testcase_13 AC 136 ms
14,464 KB
testcase_14 AC 368 ms
21,248 KB
testcase_15 AC 31 ms
10,880 KB
testcase_16 AC 291 ms
19,072 KB
testcase_17 AC 350 ms
20,736 KB
testcase_18 AC 254 ms
17,408 KB
testcase_19 AC 365 ms
20,736 KB
testcase_20 AC 107 ms
13,056 KB
testcase_21 AC 297 ms
20,224 KB
testcase_22 AC 193 ms
15,872 KB
testcase_23 AC 64 ms
11,904 KB
testcase_24 AC 100 ms
13,312 KB
testcase_25 AC 97 ms
13,184 KB
testcase_26 AC 439 ms
22,656 KB
testcase_27 WA -
testcase_28 AC 504 ms
31,232 KB
testcase_29 WA -
testcase_30 AC 492 ms
26,496 KB
testcase_31 AC 503 ms
29,696 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)

for i in range(N):
    if len(links[i]) != 1:
        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