結果
問題 |
No.3013 ハチマキ買い星人
|
ユーザー |
|
提出日時 | 2025-01-25 17:49:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 811 ms / 2,000 ms |
コード長 | 1,885 bytes |
コンパイル時間 | 291 ms |
コンパイル使用メモリ | 82,696 KB |
実行使用メモリ | 141,952 KB |
最終ジャッジ日時 | 2025-01-25 23:59:47 |
合計ジャッジ時間 | 20,386 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
# 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] teisu = 1000000 def encode(x,y): return x * teisu + y def decode(val): return divmod(val, teisu) 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=False) heap.push(encode(0, 0)) while heap.hq: cost, city = decode(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(encode(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)