結果
問題 | No.1424 Ultrapalindrome |
ユーザー | yuusanlondon |
提出日時 | 2021-03-12 21:32:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 316 ms / 2,000 ms |
コード長 | 891 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 86,860 KB |
実行使用メモリ | 103,616 KB |
最終ジャッジ日時 | 2023-08-04 18:55:54 |
合計ジャッジ時間 | 7,114 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,284 KB |
testcase_01 | AC | 73 ms
71,180 KB |
testcase_02 | AC | 75 ms
71,204 KB |
testcase_03 | AC | 77 ms
71,136 KB |
testcase_04 | AC | 76 ms
71,212 KB |
testcase_05 | AC | 76 ms
71,144 KB |
testcase_06 | AC | 73 ms
71,296 KB |
testcase_07 | AC | 74 ms
71,180 KB |
testcase_08 | AC | 75 ms
71,140 KB |
testcase_09 | AC | 191 ms
86,908 KB |
testcase_10 | AC | 187 ms
86,860 KB |
testcase_11 | AC | 162 ms
83,888 KB |
testcase_12 | AC | 182 ms
86,580 KB |
testcase_13 | AC | 123 ms
78,588 KB |
testcase_14 | AC | 171 ms
85,744 KB |
testcase_15 | AC | 75 ms
70,956 KB |
testcase_16 | AC | 150 ms
82,952 KB |
testcase_17 | AC | 163 ms
83,776 KB |
testcase_18 | AC | 237 ms
84,360 KB |
testcase_19 | AC | 288 ms
87,152 KB |
testcase_20 | AC | 182 ms
80,164 KB |
testcase_21 | AC | 255 ms
85,108 KB |
testcase_22 | AC | 220 ms
82,168 KB |
testcase_23 | AC | 149 ms
78,852 KB |
testcase_24 | AC | 184 ms
79,936 KB |
testcase_25 | AC | 184 ms
79,996 KB |
testcase_26 | AC | 316 ms
88,616 KB |
testcase_27 | AC | 228 ms
90,648 KB |
testcase_28 | AC | 171 ms
89,312 KB |
testcase_29 | AC | 188 ms
91,000 KB |
testcase_30 | AC | 274 ms
101,468 KB |
testcase_31 | AC | 280 ms
103,616 KB |
ソースコード
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')