Army of Clones
시간 제한1.5초메모리 제한512 MB
무방향 그래프와 방마다의 드로이드 수가 주어질 때, 클론이 방 n에 도달할 수 있는 최대 시작 클론 수를 구한다.
문제
The army of clones sneaked into the spaceship "Death Star" to help Luke Skywalker battling with Darth Vader. The spaceship consists of rooms and bidirectional passages between them. The clones start in the room 1 and want to go to the room , where Luke is.
However every room is guarded by droids, room is guarded by droids. When the clones appear in the room, the battle between them and the droids starts. If the number of clones is greater than the number of droids, the clones will kill all the droids and all the clones will stay alive. Otherwise the clones will kill all droids as well, but they will lose half of the army: if there are clones at the beginning of the battle, then there will be clones at the end of battle, rounded down. The clones have to battle in all rooms they would visit, including rooms 1 and .
Help the captain of the army to count the maximum number of clones that can come from the room 1 to the room .
입력
The first line contains two integers and --- number of rooms and passages in "Death Star" ().
The following lines describe passages: the -th passage is described by two integers and --- the rooms that are connected by the passage (, ). It is guaranteed that every pair of rooms is connected by at most one passage.
The next line contains an integer --- the number of clones in the army ().
The last line contains integers --- the number of droids in the rooms ().
출력
Print a single integer --- the maximum number of clones that can go from room 1 to room . If there is no path to follow, so that at least one clone survives, print 0.