結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-12 21:52:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 97,328 KB
最終ジャッジ日時 2024-04-22 12:47:13
合計ジャッジ時間 6,148 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,140 KB
testcase_01 AC 42 ms
54,560 KB
testcase_02 AC 42 ms
55,320 KB
testcase_03 AC 42 ms
54,236 KB
testcase_04 AC 43 ms
54,404 KB
testcase_05 AC 41 ms
54,864 KB
testcase_06 AC 43 ms
54,000 KB
testcase_07 AC 43 ms
54,760 KB
testcase_08 WA -
testcase_09 AC 221 ms
87,628 KB
testcase_10 AC 222 ms
87,644 KB
testcase_11 AC 180 ms
84,608 KB
testcase_12 AC 211 ms
86,940 KB
testcase_13 AC 113 ms
78,256 KB
testcase_14 AC 184 ms
85,252 KB
testcase_15 AC 45 ms
54,616 KB
testcase_16 AC 160 ms
82,688 KB
testcase_17 AC 189 ms
85,000 KB
testcase_18 AC 153 ms
81,512 KB
testcase_19 AC 212 ms
84,284 KB
testcase_20 AC 109 ms
77,700 KB
testcase_21 AC 165 ms
82,504 KB
testcase_22 AC 139 ms
80,672 KB
testcase_23 AC 88 ms
77,356 KB
testcase_24 AC 105 ms
77,928 KB
testcase_25 AC 102 ms
77,940 KB
testcase_26 AC 228 ms
85,796 KB
testcase_27 WA -
testcase_28 AC 157 ms
89,528 KB
testcase_29 AC 160 ms
89,552 KB
testcase_30 AC 189 ms
97,328 KB
testcase_31 AC 167 ms
96,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

cand = []
for i in range(n):
    if len(e[i]) == 1:
        cand.append(i)

def search(ind):
    dis = [10**10]*n
    dis[cand[ind]] = 0

    q = deque([cand[ind]])
    while q:
        now = q.popleft()
        for nex in e[now]:
            if dis[nex] > dis[now]+1:
                dis[nex] = dis[now]+1
                q.append(nex)
    num = dis[cand[(ind+1)%len(cand)]]
    for i in cand:
        if i != cand[ind] and num != dis[i]:
            print("No")
            exit()
search(0)
search(1)
print("Yes")
0