結果
| 問題 |
No.1424 Ultrapalindrome
|
| コンテスト | |
| ユーザー |
yuusanlondon
|
| 提出日時 | 2021-03-12 21:32:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 302 ms / 2,000 ms |
| コード長 | 891 bytes |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 99,848 KB |
| 最終ジャッジ日時 | 2024-10-14 16:08:38 |
| 合計ジャッジ時間 | 5,979 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import heapq
INF=10**9
def Dijkstra(graph, start):
dist=[INF]*len(graph)
parent=[INF]*len(graph)
queue=[(0, start)]
dist[start]=0
while queue:
path_len, v=heapq.heappop(queue)
if path_len==dist[v]:
for w in graph[v]:
if dist[w]>path_len+1:
parent[w]=v
heapq.heappush(queue, (path_len+1, w))
dist[w]=path_len+1
return (dist,parent)
n=int(input())
graph=[]
for i in range(n):
graph.append([])
for i in range(n-1):
a,b=map(int,input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
flag=0
fail=0
for i in range(n):
if len(graph[i])>2:
if flag==1:
fail=1
flag=1
start=i
if fail:
print('No')
exit()
if flag==0:
print('Yes')
exit()
dist,parent=Dijkstra(graph,start)
k=set()
for i in range(n):
if len(graph[i])==1:
k.add(dist[i])
if len(k)==1:
print('Yes')
else:
print('No')
yuusanlondon