ZAFT is about to fire its superweapon GENESIS and destroy the Earth! It's up to Athrun to stop them from activating the GENESIS. In order to activate the GENESIS, a ship must send a signal to GENESIS telling it to activate, but sometimes the ship's range isn't far enough and cannot reach the GENESIS. To reach GENESIS, a ship will send a signal to neighbouring ships, telling them to send a signal to other neighbouring ships, eventually reaching the GENESIS. Athrun knows that there are ships labeled , with GENESIS labeled . Destroying the ship requires energy. Athrun also knows that there are connections of the form between ships. Each connection means that ship can pass a one-way signal to ship . Athrun would like to destroy a number of ships so that ship cannot send a signal to ship . Of course, the GENESIS cannot be destroyed.
He would like to spend the least amount of energy in disconnecting the ships, and has asked you to help him find this amount.
Input Specification
First line contains the integer . The next lines contain the values .
Line contains the integer . The next lines contain two integers, and denoting a connection between ship and ship .
Output Specification
An integer denoting the minimum energy required to cut connections between ship and .
Sample Input
3
4
3
2
1 2
2 3
Sample Output
3
Comments
MLE
Any hints as to why I'm MLEing?
Nvm, I recursed too early
It looks like you have an infinite loop (seems to be the DFS function).
Thx for the suggestion, but I thought that that was part of the algorithm.
I was suggesting that your dfs function was never finishing, but perhaps I was wrong (I probably was).
Is my approach to this problem wrong?
Is algorithm too slow?
If ship 1 cannot be destroyed, what's the meaning of ? Is it the energy required to destroy ship 1? If I just ignore , my solution got WA. But if I consider , it is correct.