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.
Medium6GraphShortest pathGreedyNo attempts yetTime limit2sMemory limit512 MBThe country of nein declared war on the country of sys. Between the two countries there are n 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 ai troops at stronghold i, that stronghold survives every attack. With fewer troops it falls.
The invasion starts at stronghold n, the capital of nein, and spreads through fallen strongholds. If it reaches stronghold 1, the capital of sys, sys loses the war. Neither capital can be garrisoned.
Yeongseon, the king of sys, has k troops. Decide whether he can distribute them among the strongholds so that the invasion never reaches stronghold 1. The total number of troops stationed cannot exceed k.
The first line contains the number of strongholds n, the number of roads m, and the number of troops k. (2≤n≤100, 1≤m≤1000, 1≤k≤10000)
The second line contains a1,a2,…,an, where ai is the number of troops needed to hold stronghold i. (1≤ai≤1000) Neither capital can be garrisoned, so a1 and an are always −1.
Each of the next m lines contains the numbers u and v of the two strongholds joined by a road. (1≤u,v≤n, u=v) Roads are bidirectional, and the same pair can appear more than once.
Print YES if k troops can be placed so that the invasion is stopped, and NO otherwise.