結果

問題 No.1424 Ultrapalindrome
ユーザー gorugo30gorugo30
提出日時 2021-03-16 19:40:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 93,544 KB
最終ジャッジ日時 2024-04-25 21:27:17
合計ジャッジ時間 5,158 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,128 KB
testcase_01 AC 41 ms
54,760 KB
testcase_02 AC 36 ms
53,052 KB
testcase_03 AC 36 ms
52,944 KB
testcase_04 AC 36 ms
52,740 KB
testcase_05 AC 36 ms
54,304 KB
testcase_06 AC 40 ms
55,484 KB
testcase_07 AC 39 ms
53,912 KB
testcase_08 AC 36 ms
53,528 KB
testcase_09 AC 147 ms
85,316 KB
testcase_10 AC 157 ms
85,432 KB
testcase_11 AC 124 ms
82,476 KB
testcase_12 AC 150 ms
85,088 KB
testcase_13 AC 86 ms
78,028 KB
testcase_14 AC 135 ms
82,704 KB
testcase_15 AC 39 ms
53,480 KB
testcase_16 AC 113 ms
81,912 KB
testcase_17 AC 119 ms
82,500 KB
testcase_18 AC 132 ms
81,996 KB
testcase_19 AC 153 ms
85,044 KB
testcase_20 AC 98 ms
78,368 KB
testcase_21 AC 122 ms
82,500 KB
testcase_22 AC 106 ms
81,264 KB
testcase_23 AC 79 ms
77,888 KB
testcase_24 AC 84 ms
78,280 KB
testcase_25 AC 92 ms
78,172 KB
testcase_26 AC 179 ms
86,808 KB
testcase_27 AC 177 ms
89,996 KB
testcase_28 AC 124 ms
85,928 KB
testcase_29 AC 149 ms
89,460 KB
testcase_30 AC 152 ms
92,828 KB
testcase_31 AC 153 ms
93,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
deg = [0] * N
adj = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    adj[a].append(b)
    adj[b].append(a)
aiueo = len(deg) - deg.count(2) - deg.count(1)
if aiueo > 1:
    print("No")
    exit()
if aiueo == 0:
    print("Yes")
    exit()
from collections import deque
r = deg.index(max(deg))
dep = [-1] * N
dep[r] = 0
qu = deque([r])
while len(qu):
    v = qu.popleft()
    for nv in adj[v]:
        if dep[nv] == -1:
            dep[nv] = dep[v] + 1
            qu.append(nv)
d = -1
for i in range(N):
    if deg[i] != 1:
        continue
    if d != -1 and d != dep[i]:
        print("No")
        exit()
    d = dep[i]
print("Yes")
0