No.95 Alice and Graph
Description
Alice was given an undirected graph by her mother as a birthday gift.
Then, as usual, Alice is now playing a game with the graph.
The graph has
When the game starts, Alice is in node
Then Alice will be allowed to move at most
At each move, Alice can go to an adjacent node through an edge, and collect the coins at the node.
The question is that what is the maximum number of coins can Alice collect?
Here please note that Alice does not have to go back to node
Input
There is at most one edge between any pair of nodes.
Please do NOT assume that the graph is connected.
Output
Output the answer in one line.
One newline-character will be needed at the end of output.
Be careful that the answer may not fit a 32-bit integer type, but it will fit a 64-bit integer type.
Samples
Sample 1
Input
4 3 1 1 2 1 3 1 4
Output
7
Alice can move node
Sample 2
Input
5 4 4 3 4 4 1 1 5 5 2
Output
25
The graph is as follows:
The optimal sequence of moves of Alice is
Thus the answer will be
Sample 3
Input
20 21 15 8 16 2 11 7 5 6 8 17 8 4 17 15 20 13 14 5 11 2 12 19 18 11 18 10 19 3 7 9 8 20 2 3 19 17 15 3 2 17 11 1 9
Output
1036150
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。