結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-12 21:54:19
言語 PyPy3
(7.3.13)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 739 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 100,668 KB
最終ジャッジ日時 2023-08-04 19:01:10
合計ジャッジ時間 6,788 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,464 KB
testcase_01 AC 84 ms
71,616 KB
testcase_02 AC 86 ms
71,756 KB
testcase_03 AC 85 ms
71,552 KB
testcase_04 AC 86 ms
71,612 KB
testcase_05 AC 83 ms
71,628 KB
testcase_06 AC 82 ms
71,552 KB
testcase_07 AC 84 ms
71,620 KB
testcase_08 AC 87 ms
71,676 KB
testcase_09 AC 213 ms
89,840 KB
testcase_10 AC 215 ms
89,532 KB
testcase_11 AC 185 ms
85,404 KB
testcase_12 AC 206 ms
89,032 KB
testcase_13 AC 143 ms
80,604 KB
testcase_14 AC 191 ms
86,068 KB
testcase_15 AC 85 ms
71,632 KB
testcase_16 AC 175 ms
84,532 KB
testcase_17 AC 181 ms
85,612 KB
testcase_18 AC 174 ms
83,888 KB
testcase_19 AC 211 ms
85,536 KB
testcase_20 AC 144 ms
80,160 KB
testcase_21 AC 187 ms
84,512 KB
testcase_22 AC 155 ms
81,720 KB
testcase_23 AC 123 ms
77,888 KB
testcase_24 AC 141 ms
79,684 KB
testcase_25 AC 139 ms
79,696 KB
testcase_26 AC 228 ms
87,648 KB
testcase_27 WA -
testcase_28 AC 189 ms
90,528 KB
testcase_29 AC 188 ms
90,716 KB
testcase_30 AC 205 ms
99,328 KB
testcase_31 AC 192 ms
100,668 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)
if len(cand) > 2:
    search(2)
print("Yes")
0