結果
問題 |
No.1480 Many Complete Graphs
|
ユーザー |
![]() |
提出日時 | 2025-06-12 12:56:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,229 bytes |
コンパイル時間 | 329 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 105,688 KB |
最終ジャッジ日時 | 2025-06-12 13:02:22 |
合計ジャッジ時間 | 12,498 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 WA * 11 |
ソースコード
import sys import heapq def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 adj = [[] for _ in range(N + M + 1)] # Nodes are 1..N, virtual nodes are N+1..N+M for op in range(M): k = int(input[ptr]) ptr += 1 c = int(input[ptr]) ptr += 1 s = list(map(int, input[ptr:ptr + k])) ptr += k virtual_node = N + 1 + op floor_c = c // 2 ceil_c = (c + 1) // 2 for a in s: cost_to_virtual = (a + 1) // 2 + floor_c adj[a].append((virtual_node, cost_to_virtual)) cost_from_virtual = (a) // 2 + ceil_c adj[virtual_node].append((a, cost_from_virtual)) INF = 1 << 60 dist = [INF] * (N + M + 1) dist[1] = 0 heap = [] heapq.heappush(heap, (0, 1)) while heap: d, u = heapq.heappop(heap) if d > dist[u]: continue for v, w in adj[u]: if dist[v] > d + w: dist[v] = d + w heapq.heappush(heap, (dist[v], v)) if dist[N] == INF: print(-1) else: print(dist[N]) if __name__ == "__main__": main()