Hold off the enemy
Time limit2sMemory limit512 MB
Given troop costs on strongholds, decide whether k troops can block every path from node n to node 1 before the invasion reaches the capital.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Greedy
- Solved
- No attempts yet
Problem
The country of nein declared war on the country of sys. Between the two countries there are strongholds, and some pairs of strongholds are joined by roads. Once a stronghold falls, every stronghold joined to it by a road becomes the next target.
Each stronghold has a troop count that holds it for certain. If you station troops at stronghold , that stronghold survives every attack. With fewer troops it falls.
The invasion starts at stronghold , the capital of nein, and spreads through fallen strongholds. If it reaches stronghold , the capital of sys, sys loses the war. Neither capital can be garrisoned.
Yeongseon, the king of sys, has troops. Decide whether he can distribute them among the strongholds so that the invasion never reaches stronghold . The total number of troops stationed cannot exceed .
Input
The first line contains the number of strongholds , the number of roads , and the number of troops . (, , )
The second line contains , where is the number of troops needed to hold stronghold . () Neither capital can be garrisoned, so and are always .
Each of the next lines contains the numbers and of the two strongholds joined by a road. (, ) Roads are bidirectional, and the same pair can appear more than once.
Output
Print YES if troops can be placed so that the invasion is stopped, and NO otherwise.