結果
| 問題 |
No.3013 ハチマキ買い星人
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-03 18:45:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 766 ms / 2,000 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 488 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 116,096 KB |
| 最終ジャッジ日時 | 2025-01-25 21:56:46 |
| 合計ジャッジ時間 | 19,400 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge9 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
from heapq import heappop, heappush
INF = 10**18
def dijkstra(start, graph):
n = len(graph)
dist = [INF] * n
dist[start] = 0
pq = [(0, start)]
while pq:
now_d, now_v = heappop(pq)
if now_d > dist[now_v]:
continue
for next_v, cost in graph[now_v]:
next_d = now_d + cost
if next_d < dist[next_v]:
dist[next_v] = next_d
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 = [INF] * N
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 and dist[i] <= Y:
ans = max(ans, (Y - dist[i]) // shops[i])
print(ans)