結果
問題 |
No.3013 ハチマキ買い星人
|
ユーザー |
|
提出日時 | 2025-01-25 17:47:48 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,757 bytes |
コンパイル時間 | 362 ms |
コンパイル使用メモリ | 82,884 KB |
実行使用メモリ | 275,724 KB |
最終ジャッジ日時 | 2025-01-26 00:00:36 |
合計ジャッジ時間 | 84,740 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge7 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 TLE * 25 |
ソースコード
# library from https://prd-xxx.hateblo.jp/entry/2019/06/24/235844 import heapq class Reverse: def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __repr__(self): return repr(self.val) class Heapq: def __init__(self, arr, desc = False): if desc: for i in range(len(arr)): arr[i] = Reverse(arr[i]) self.desc = desc self.hq = arr heapq.heapify(self.hq) def pop(self): if self.desc: return heapq.heappop(self.hq).val else: return heapq.heappop(self.hq) def push(self, a): if self.desc: heapq.heappush(self.hq, Reverse(a)) else: heapq.heappush(self.hq, a) def top(self): if self.desc: self.hq[0].val else: return self.hq[0] n,m,p,y = map(int, input().split()) abc = [list(map(int, input().split())) for i in range(m)] de = [list(map(int, input().split())) for i in range(p)] graph = [[] for i in range(n)] for a,b,c in abc: a -= 1 b -= 1 graph[a].append((b,c)) graph[b].append((a,c)) # hachi = [1 << 60 for i in range(n)] # for d,e in de: # d -= 1 # hachi[d] = e state = [1 << 60 for i in range(n)] state[0] = 0 heap = Heapq([], desc=True) heap.push((0, 0)) while heap.hq: cost, city = heap.pop() if state[city] < cost: continue for ncity, nc in graph[city]: ncost = cost + nc if state[ncity] <= ncost: continue state[ncity] = ncost heap.push((ncost, ncity)) ans = 0 for d,e in de: d -= 1 cost = state[d] if cost > y: continue res = y - cost tans = res // e ans = max(ans, tans) print(ans)