package main import . "fmt" import . "os" import bf "bufio" import "container/heap" type Edge struct { cost int64 a,b int } func main() { rd:=bf.NewReader(Stdin) var n,m,p int var y int64 Fscan(rd,&n,&m,&p,&y) graph := make([][]*Edge, n+1) for i:=0;i 0 { item := heap.Pop(&pq).(*Item) visited[item.id] = true if hachi[item.id] > 0 { nums := (y-item.cost)/hachi[item.id] if nums > ans { ans = nums } } for _, e := range graph[item.id] { next := e.a+e.b-item.id if visited[next] { continue } if cache[next] == nil { cache[next] = &Item{ id : next, index : -1, cost : e.cost + item.cost, } heap.Push(&pq, cache[next]) } else { newcost := e.cost + item.cost if newcost < cache[next].cost { cache[next].cost = newcost heap.Fix(&pq, cache[next].index) } } } } Println(ans) } type Item struct { id int index int cost int64 } type PQ []*Item func (pq PQ)Len() int { return len(pq) } func (pq PQ)Less(i,j int) bool { return pq[i].cost < pq[j].cost } func (pq PQ)Swap(i, j int) { pq[i],pq[j] = pq[j],pq[i] pq[i].index = i pq[j].index = j } func (pq*PQ)Push(x any) { item := x.(*Item) item.index = len(*pq) *pq = append(*pq, item) } func (pq*PQ)Pop() any { old := *pq n := len(old) *pq = old[:n-1] res := old[n-1] res.index = -1 old[n-1] = nil return res }