結果
問題 |
No.3013 ハチマキ買い星人
|
ユーザー |
![]() |
提出日時 | 2025-01-26 17:49:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,071 ms / 2,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 697 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 127,488 KB |
最終ジャッジ日時 | 2025-01-26 17:50:16 |
合計ジャッジ時間 | 25,005 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
from collections import defaultdict, Counter, deque from itertools import groupby, accumulate, combinations, permutations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from operator import itemgetter import math from heapq import heapify, heappush, heappop LMI=lambda:list(map(int, input().split())) LMS=lambda:list(map(str, input().split())) MI=lambda:map(int, input().split()) MS=lambda:map(str, input().split()) II=lambda:int(input()) IS=lambda:input().split() LI=lambda:list(input()) 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=MI() G=[[] for i in range(N)] Shop=[] for i in range(M): a,b,c=MI() a-=1 b-=1 G[a].append((b, c)) G[b].append((a, c)) for i in range(P): d, e=MI() Shop.append([d, e]) result=dijkstra(0, G) ans=0 for de in Shop: ans=max(ans, max(0, Y-result[de[0]-1])//de[1]) print(ans)