A survey network has n beacons (numbered 0 to n-1) linked by one-way cables. Each cable carries a signal from its start beacon to its end beacon at a positive integer cost.
Starting from beacon s, a beacon is said to be within budget if the minimum total cost to reach it from s is at most B. The source s itself is within budget (its cost is 0, and B >= 0). Count how many beacons are within budget.
Line 1: four integers n, m, s, and B.
Each of the next m lines: three integers u v w, a one-way cable from beacon u to beacon v with cost w.
A single integer: the number of beacons (including s) whose shortest cost from s is at most B.
Example 1
Input
4 4 0 4 0 1 2 1 2 2 0 3 10 2 3 1
Expected
3
Explanation
Distances from 0: 0,2,4,5. With budget 4, beacons 0,1,2 qualify (distance 0,2,4) but beacon 3 (distance 5) does not: count 3.
Example 2
Input
3 1 0 3 0 1 5
Expected
1
Explanation
Distances: beacon 0 is 0, beacon 1 is 5 (over budget), beacon 2 is unreachable. Only beacon 0 is within budget: count 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →