結果
問題 | No.1480 Many Complete Graphs |
ユーザー |
![]() |
提出日時 | 2025-06-12 16:10:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,204 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 83,000 KB |
実行使用メモリ | 487,400 KB |
最終ジャッジ日時 | 2025-06-12 16:10:52 |
合計ジャッジ時間 | 17,316 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 TLE * 1 -- * 31 |
ソースコード
import sys import heapq def main(): input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 M = int(data[idx]) idx += 1 adj = [[] for _ in range(N+1)] # 1-based for _ in range(M): k_i = int(data[idx]) idx += 1 c_i = int(data[idx]) idx += 1 s = list(map(int, data[idx:idx + k_i])) idx += k_i # Add all pairs for x in range(k_i): for y in range(x+1, k_i): a = s[x] b = s[y] w = (a + b + 1) // 2 + c_i adj[a].append((b, w)) adj[b].append((a, w)) # Dijkstra's algorithm INF = float('inf') dist = [INF] * (N + 1) dist[1] = 0 heap = [] heapq.heappush(heap, (0, 1)) while heap: current_dist, u = heapq.heappop(heap) if current_dist > dist[u]: continue if u == N: print(current_dist) return for v, w in adj[u]: if dist[v] > dist[u] + w: dist[v] = dist[u] + w heapq.heappush(heap, (dist[v], v)) print(-1) if __name__ == '__main__': main()