結果

問題 No.1424 Ultrapalindrome
ユーザー tobusakanatobusakana
提出日時 2022-10-14 22:14:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 98,660 KB
最終ジャッジ日時 2023-09-08 22:00:57
合計ジャッジ時間 7,104 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,108 KB
testcase_01 AC 71 ms
70,856 KB
testcase_02 AC 71 ms
71,052 KB
testcase_03 AC 73 ms
71,020 KB
testcase_04 AC 73 ms
71,272 KB
testcase_05 AC 74 ms
70,880 KB
testcase_06 AC 73 ms
71,016 KB
testcase_07 AC 70 ms
71,184 KB
testcase_08 AC 72 ms
71,308 KB
testcase_09 AC 192 ms
86,276 KB
testcase_10 AC 195 ms
86,300 KB
testcase_11 AC 159 ms
82,644 KB
testcase_12 AC 191 ms
85,716 KB
testcase_13 AC 122 ms
78,748 KB
testcase_14 AC 165 ms
83,072 KB
testcase_15 AC 74 ms
71,200 KB
testcase_16 AC 157 ms
82,160 KB
testcase_17 AC 161 ms
82,876 KB
testcase_18 AC 168 ms
82,364 KB
testcase_19 AC 204 ms
85,088 KB
testcase_20 AC 130 ms
78,504 KB
testcase_21 AC 179 ms
83,100 KB
testcase_22 AC 153 ms
81,284 KB
testcase_23 AC 111 ms
78,104 KB
testcase_24 AC 131 ms
78,500 KB
testcase_25 AC 127 ms
78,616 KB
testcase_26 AC 231 ms
86,104 KB
testcase_27 AC 229 ms
90,856 KB
testcase_28 AC 162 ms
88,912 KB
testcase_29 AC 175 ms
89,932 KB
testcase_30 AC 188 ms
98,488 KB
testcase_31 AC 193 ms
98,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for i in range(N)]
indegree = [0] * N
for _ in range(N - 1):
    a,b = map(int,input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    indegree[a - 1] += 1
    indegree[b - 1] += 1
    
uni = -1
for v in range(N):
    if indegree[v] > 2:
        if uni != -1:
            print("No")
            exit(0)
        uni = v

if uni == -1:
    print("Yes")
    exit(0)
    
stack = []
stack.append([uni, 0])
dist = [-1] * N
while stack:
    v, d = stack.pop()
    if dist[v] != -1:
        continue
    dist[v] = d
    for child in G[v]:
        if dist[child] != -1:
            continue
        stack.append([child, d + 1])

ds = set()        
for v in range(N):
    if indegree[v] == 1:
        ds.add(dist[v])
        
if len(ds) == 1:
    print("Yes")
else:
    print("No")
0