結果

問題 No.1424 Ultrapalindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-03-13 09:31:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 98,392 KB
最終ジャッジ日時 2024-04-23 03:15:59
合計ジャッジ時間 5,067 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,228 KB
testcase_01 AC 40 ms
53,936 KB
testcase_02 AC 42 ms
54,420 KB
testcase_03 AC 40 ms
54,020 KB
testcase_04 AC 41 ms
55,132 KB
testcase_05 AC 40 ms
53,996 KB
testcase_06 AC 41 ms
54,404 KB
testcase_07 AC 41 ms
55,360 KB
testcase_08 AC 40 ms
53,820 KB
testcase_09 AC 166 ms
86,708 KB
testcase_10 AC 165 ms
87,016 KB
testcase_11 AC 135 ms
82,812 KB
testcase_12 AC 159 ms
86,424 KB
testcase_13 AC 96 ms
78,220 KB
testcase_14 AC 137 ms
83,324 KB
testcase_15 AC 44 ms
55,088 KB
testcase_16 AC 137 ms
82,392 KB
testcase_17 AC 138 ms
83,480 KB
testcase_18 AC 137 ms
81,740 KB
testcase_19 AC 172 ms
84,284 KB
testcase_20 AC 101 ms
78,224 KB
testcase_21 AC 142 ms
82,060 KB
testcase_22 AC 127 ms
80,604 KB
testcase_23 AC 86 ms
77,720 KB
testcase_24 AC 97 ms
77,896 KB
testcase_25 AC 98 ms
77,764 KB
testcase_26 AC 188 ms
86,156 KB
testcase_27 AC 201 ms
90,896 KB
testcase_28 AC 138 ms
87,696 KB
testcase_29 AC 148 ms
88,672 KB
testcase_30 AC 161 ms
96,844 KB
testcase_31 AC 162 ms
98,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

c = 0
cand = []
ind = 0
for i in range(1,n+1):
    if len(e[i]) == 1:
        cand.append(i)
    if len(e[i]) >= 3:
        c += 1
        ind = i
if c == 0:
    print("Yes")
    exit()
if c >= 2:
    print("No")
    exit()

dis = [10**10]*(n+1)
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)

d = dis[cand[0]]
for i in cand:
    if d != dis[i]:
        print("No")
        exit()
print("Yes")
0