結果

問題 No.1424 Ultrapalindrome
ユーザー tobusakanatobusakana
提出日時 2022-10-14 21:31:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,652 KB
実行使用メモリ 98,400 KB
最終ジャッジ日時 2023-09-08 20:20:20
合計ジャッジ時間 7,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,168 KB
testcase_01 AC 67 ms
71,056 KB
testcase_02 AC 71 ms
71,052 KB
testcase_03 AC 68 ms
70,940 KB
testcase_04 AC 67 ms
70,884 KB
testcase_05 AC 68 ms
71,152 KB
testcase_06 AC 67 ms
71,160 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 222 ms
87,036 KB
testcase_10 AC 210 ms
86,900 KB
testcase_11 AC 177 ms
84,460 KB
testcase_12 AC 202 ms
86,500 KB
testcase_13 AC 140 ms
79,084 KB
testcase_14 AC 179 ms
85,324 KB
testcase_15 AC 69 ms
71,228 KB
testcase_16 AC 160 ms
82,812 KB
testcase_17 AC 175 ms
84,764 KB
testcase_18 AC 149 ms
81,920 KB
testcase_19 AC 175 ms
84,608 KB
testcase_20 AC 122 ms
78,496 KB
testcase_21 AC 162 ms
83,324 KB
testcase_22 AC 140 ms
81,280 KB
testcase_23 AC 108 ms
77,908 KB
testcase_24 AC 117 ms
78,264 KB
testcase_25 AC 120 ms
78,268 KB
testcase_26 AC 192 ms
85,692 KB
testcase_27 WA -
testcase_28 AC 175 ms
89,432 KB
testcase_29 WA -
testcase_30 AC 184 ms
98,340 KB
testcase_31 AC 194 ms
98,400 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
    
# 次数1のある点から、他の全ての点への距離が同じであればOK
start = -1
for v in range(N):
    if indegree[v] == 1:
        start = v
        break

stack = []
dist = [-1] * N
stack.append([start, 0])
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 v == start:
        continue
    if indegree[v] == 1:
        ds.add(dist[v])
        
if len(ds) > 1:
    print("No")
else:
    print("Yes")
    
0