結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-12 21:54:19
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 739 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 98,232 KB
最終ジャッジ日時 2024-04-22 17:05:46
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,648 KB
testcase_01 AC 40 ms
54,784 KB
testcase_02 AC 40 ms
54,664 KB
testcase_03 AC 40 ms
53,932 KB
testcase_04 AC 41 ms
54,624 KB
testcase_05 AC 40 ms
54,296 KB
testcase_06 AC 40 ms
54,096 KB
testcase_07 AC 42 ms
55,444 KB
testcase_08 AC 41 ms
55,300 KB
testcase_09 AC 188 ms
87,552 KB
testcase_10 AC 202 ms
87,724 KB
testcase_11 AC 159 ms
84,560 KB
testcase_12 AC 177 ms
87,536 KB
testcase_13 AC 108 ms
78,716 KB
testcase_14 AC 166 ms
85,792 KB
testcase_15 AC 44 ms
55,544 KB
testcase_16 AC 144 ms
82,564 KB
testcase_17 AC 164 ms
85,012 KB
testcase_18 AC 145 ms
81,944 KB
testcase_19 AC 190 ms
84,748 KB
testcase_20 AC 105 ms
78,340 KB
testcase_21 AC 164 ms
82,956 KB
testcase_22 AC 130 ms
81,020 KB
testcase_23 AC 87 ms
77,868 KB
testcase_24 AC 104 ms
77,936 KB
testcase_25 AC 98 ms
78,148 KB
testcase_26 AC 223 ms
86,148 KB
testcase_27 WA -
testcase_28 AC 151 ms
89,356 KB
testcase_29 AC 154 ms
89,236 KB
testcase_30 AC 170 ms
98,232 KB
testcase_31 AC 161 ms
96,600 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