結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-12 21:47:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 98,556 KB
最終ジャッジ日時 2024-04-22 12:38:06
合計ジャッジ時間 5,515 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,632 KB
testcase_01 AC 43 ms
54,144 KB
testcase_02 AC 42 ms
53,888 KB
testcase_03 AC 43 ms
54,016 KB
testcase_04 AC 43 ms
53,632 KB
testcase_05 AC 43 ms
54,144 KB
testcase_06 AC 43 ms
53,760 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 224 ms
88,684 KB
testcase_10 AC 227 ms
88,832 KB
testcase_11 AC 175 ms
84,224 KB
testcase_12 AC 212 ms
88,236 KB
testcase_13 AC 115 ms
78,580 KB
testcase_14 AC 188 ms
86,192 KB
testcase_15 AC 45 ms
55,040 KB
testcase_16 AC 158 ms
83,456 KB
testcase_17 AC 185 ms
85,820 KB
testcase_18 AC 145 ms
81,664 KB
testcase_19 AC 185 ms
84,336 KB
testcase_20 AC 106 ms
78,416 KB
testcase_21 AC 157 ms
82,716 KB
testcase_22 AC 132 ms
80,656 KB
testcase_23 AC 89 ms
77,696 KB
testcase_24 AC 102 ms
78,112 KB
testcase_25 AC 102 ms
77,852 KB
testcase_26 AC 206 ms
85,856 KB
testcase_27 WA -
testcase_28 AC 155 ms
89,592 KB
testcase_29 WA -
testcase_30 AC 167 ms
98,556 KB
testcase_31 AC 171 ms
98,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

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

ind = cand[0]
dis = [10**10]*n
dis[ind] = 0

q = deque([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[1]]
for i in cand[2:]:
    if num != dis[i]:
        print("No")
        exit()
print("Yes")
0