#C5032. Maximum Checkpoints Under Budget
Maximum Checkpoints Under Budget
Maximum Checkpoints Under Budget
You are given a network of checkpoints connected by bidirectional paths. Each path between two checkpoints has an associated travel cost. Starting from checkpoint 0, your goal is to determine the maximum number of checkpoints you can visit such that the cumulative cost to reach each checkpoint does not exceed a given budget B.
You must travel along the network using the available paths. If there are multiple paths to the same checkpoint, you should choose the one that minimizes the travel cost. Note that the journey starts at checkpoint 0 and the cost to remain at the starting point is zero.
Input Constraints:
- The number of checkpoints is represented by N.
- The number of paths is M.
- The travel budget is given by B.
- Every path is described by three integers u, v and c in the format: u v c, which denotes a bidirectional path between checkpoints u and v that costs c units to traverse.
Task:
Find and print the maximum number of checkpoints that can be visited (including the starting checkpoint) such that the travel cost for reaching any checkpoint along the chosen path does not exceed the budget B. If a checkpoint is unreachable within the budget, it is not counted.
Hint: A modified Dijkstra algorithm can be used to solve this problem efficiently.
inputFormat
The input is provided via stdin as follows:
- The first line contains three integers N, M, and B separated by spaces.
- The next M lines each contain three integers u, v, and c, defining a bidirectional path between checkpoint u and checkpoint v with cost c.
outputFormat
Output a single integer on stdout representing the maximum number of checkpoints that can be visited from checkpoint 0 within the provided budget B.
## sample3 3 10
0 1 5
1 2 5
0 2 10
3