Occupation
InterviewTime limit3sMemory limit1024 MB
Starting from node r, capture adjacent nodes whose requirement A_i is at most your current stamina, gain B_i for each, and find the final stamina.
Problem
You are given an undirected graph and a starting node . The nodes are numbered . To capture node , you must have at least stamina and at least one neighbor of node must already be captured. After you capture node , your stamina increases by . Capturing a node does not decrease your stamina by . Find the maximum stamina you can obtain. The start node is already captured, so your stamina at the start is .
Input
The first line contains the number of nodes , the number of edges , and the start node , separated by spaces. (; ; )
The second line contains , separated by spaces, the stamina required to capture each node. (; )
The third line contains , separated by spaces, the stamina gained by capturing each node. ()
From the fourth line onward, lines each contain two integers and , separated by a space, meaning that and are neighbors. (; )
Output
Print the maximum stamina you can obtain.