結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-03-12 21:33:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,098 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 101,056 KB
最終ジャッジ日時 2024-04-22 12:19:50
合計ジャッジ時間 4,902 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,064 KB
testcase_01 AC 45 ms
55,140 KB
testcase_02 AC 44 ms
54,724 KB
testcase_03 AC 42 ms
54,720 KB
testcase_04 AC 42 ms
54,240 KB
testcase_05 AC 42 ms
54,080 KB
testcase_06 AC 42 ms
54,992 KB
testcase_07 AC 42 ms
54,452 KB
testcase_08 WA -
testcase_09 AC 181 ms
88,592 KB
testcase_10 AC 177 ms
88,660 KB
testcase_11 AC 144 ms
85,344 KB
testcase_12 AC 164 ms
87,968 KB
testcase_13 AC 90 ms
79,000 KB
testcase_14 AC 147 ms
86,004 KB
testcase_15 AC 43 ms
54,800 KB
testcase_16 AC 127 ms
84,132 KB
testcase_17 AC 146 ms
85,136 KB
testcase_18 AC 140 ms
83,652 KB
testcase_19 AC 181 ms
85,580 KB
testcase_20 AC 93 ms
78,536 KB
testcase_21 AC 154 ms
84,196 KB
testcase_22 AC 122 ms
81,024 KB
testcase_23 AC 73 ms
75,196 KB
testcase_24 AC 93 ms
78,356 KB
testcase_25 AC 88 ms
78,472 KB
testcase_26 AC 202 ms
87,896 KB
testcase_27 WA -
testcase_28 AC 124 ms
91,348 KB
testcase_29 AC 125 ms
91,608 KB
testcase_30 AC 143 ms
101,056 KB
testcase_31 AC 130 ms
100,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

全ての葉の間の距離がひとしければおk

"""

import sys
from sys import stdin

from collections import deque
def NC_Dij(lis,start):

    ret = [float("inf")] * len(lis)
    ret[start] = 0
    
    q = deque([start])
    plis = [i for i in range(len(lis))]

    while len(q) > 0:
        now = q.popleft()

        for nex in lis[now]:

            if ret[nex] > ret[now] + 1:
                ret[nex] = ret[now] + 1
                plis[nex] = now
                q.append(nex)

    return ret,plis

N = int(stdin.readline())

lis = [ [] for i in range(N) ]

for loop in range(N-1):

    a,b = map(int,stdin.readline().split())
    a -= 1
    b -= 1

    lis[a].append(b)
    lis[b].append(a)

leaf = []
for i in range(N):
    if len(lis[i]) == 1:
        leaf.append(i)


st = leaf[0]
dis,tmp = NC_Dij(lis,st)
ld = dis[leaf[1]]

for i in range(1,len(leaf)):
    if dis[leaf[i]] != ld:
        print ("No")
        sys.exit()

st = leaf[-1]
dis,tmp = NC_Dij(lis,st)
for i in range(0,len(leaf)-1):
    if dis[leaf[i]] != ld:
        print ("No")
        sys.exit()

print ("Yes")
0