結果
問題 | No.1480 Many Complete Graphs |
ユーザー |
|
提出日時 | 2021-04-17 15:49:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 436 ms / 2,000 ms |
コード長 | 1,148 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 81,632 KB |
実行使用メモリ | 109,288 KB |
最終ジャッジ日時 | 2024-07-03 23:22:46 |
合計ジャッジ時間 | 17,958 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
from heapq import heappush, heappop from sys import stdin input = stdin.readline inf = 1 << 60 def main(): n, m = map(int, input().split()) edges = [[] for _ in range(n+m)] for i in range(n, n+m): k, c, *s = map(int, input().split()) for j in s: edges[j-1].append((c, i)) edges[i].append(j-1) # Dijkstra heap = [] heappush(heap, (0, 0, 0)) costs = [(inf,inf)] * (n+m) while heap: cost, rem, i = heappop(heap) if costs[i] < (cost,rem): continue if i < n: for c, j in edges[i]: new_cost = (cost + c + (i+1)//2, i+1 & 1) if new_cost < costs[j]: costs[j] = new_cost heappush(heap, (new_cost[0],new_cost[1],j)) else: for j in edges[i]: new_cost = (cost + (j+rem+2)//2, 0) if new_cost < costs[j]: costs[j] = new_cost heappush(heap, (new_cost[0],new_cost[1],j)) if costs[n-1] == (inf, inf): print(-1) else: print(costs[n-1][0]) main()