結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
👑 |
提出日時 | 2024-12-31 00:00:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 806 ms / 2,000 ms |
コード長 | 1,156 bytes |
コンパイル時間 | 2,485 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 140,856 KB |
最終ジャッジ日時 | 2025-01-25 22:11:32 |
合計ジャッジ時間 | 19,140 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
from collections import defaultdict from heapq import heappop, heappush INF = 10**18 def dijkstra(start, graph): n = len(graph) dist = [INF] * n dist[start] = 0 checked = [False] * n pq = [(0, start)] while len(pq) > 0: now_d, now_v = heappop(pq) if checked[now_v]: continue checked[now_v] = True for next_v, cost in graph[now_v]: if checked[next_v]: continue next_d = now_d + cost if next_d >= dist[next_v]: continue dist[next_v] = min(next_d, dist[next_v]) heappush(pq, (next_d, next_v)) return dist N, M, P, Y = map(int, input().split()) graph = [[] for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) graph[A - 1].append((B - 1, C)) graph[B - 1].append((A - 1, C)) shops = defaultdict(lambda: INF) for _ in range(P): D, E = map(int, input().split()) shops[D - 1] = min(shops[D - 1], E) dist = dijkstra(0, graph) ans = 0 for i in range(N): if shops[i] < INF: ans = max(ans, (Y - dist[i]) // shops[i]) print(ans)