結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-12 21:40:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 92,880 KB
最終ジャッジ日時 2024-04-22 12:29:31
合計ジャッジ時間 5,754 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,056 KB
testcase_01 AC 42 ms
54,668 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 42 ms
55,532 KB
testcase_05 AC 43 ms
53,548 KB
testcase_06 AC 42 ms
53,548 KB
testcase_07 AC 41 ms
55,348 KB
testcase_08 WA -
testcase_09 AC 219 ms
86,456 KB
testcase_10 AC 225 ms
86,624 KB
testcase_11 AC 175 ms
83,156 KB
testcase_12 AC 210 ms
86,460 KB
testcase_13 AC 117 ms
78,372 KB
testcase_14 AC 196 ms
84,860 KB
testcase_15 AC 45 ms
55,200 KB
testcase_16 AC 137 ms
82,016 KB
testcase_17 AC 186 ms
84,456 KB
testcase_18 AC 153 ms
82,400 KB
testcase_19 AC 194 ms
84,512 KB
testcase_20 AC 111 ms
78,092 KB
testcase_21 AC 166 ms
82,692 KB
testcase_22 AC 134 ms
80,660 KB
testcase_23 AC 88 ms
77,696 KB
testcase_24 AC 105 ms
78,420 KB
testcase_25 AC 105 ms
78,188 KB
testcase_26 AC 215 ms
87,032 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 157 ms
89,460 KB
testcase_30 AC 163 ms
92,836 KB
testcase_31 AC 165 ms
92,880 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)

M = max(count)
c = 0
d = 0
for i in range(n):
    if count[i] == M:
        c += 1
        ind = i
    if count[i] == 1:
        d += 1
if c != 1:
    print("No")
    exit()
if d == 2:
    print("Yes")
    exit()
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 = -1
for i in range(n):
    if count[i] == 1:
        if num == -1:
            num = dis[i]
        else:
            if num != dis[i]:
                print("No")
                exit()
print("Yes")
0