
Fax McClad, Croneria's richest bounty hunter, has enough reward money to start investing. He would like to invest in companies that will bring him a lot of profit. He will invest
Looking at a map of the Lylot System, there are
Ding dong!
Already,
However, since the galaxy is full of conflict, Fax is forced to only choose companies that fit the following condition: if any single planet gets destroyed, the remaining offices of that company should remain connected.
After ruling out all the companies that don't fit the condition, he moves on to maximize his profits. For every planet that hosts at least one office of a company that Fax has invested in, he will receive profit. In particular, the
Can you help Fax determine what his maximum profit will be?
Constraints
It is guaranteed that there will be at most 1 road between every pair of planets.
Subtask | Constraint | Points |
---|---|---|
1 | 10 | |
2 | 20 | |
3 | 15 | |
4 | 30 | |
5 | No additional constraints | 25 |
Input Specification
The first line of input will contain four space-separated integers,
u v
, signifying that there exists a bi-directional spaceroad connecting planet
The last line will contain
Output Specification
On a single line, output the maximum profit that Fax can receive.
Sample Input 1
8 10 1 5
1 2
2 3
3 4
4 1
1 5
5 6
6 1
3 7
7 8
8 3
10 1 10 1 2 2 2 2
Sample Output 1
22
Sample Explanation 1
The best solution is to invest in the company that has offices at cities 1, 2, 3, 4.
Sample Input 2
8 10 2 5
1 2
2 3
3 4
4 1
1 5
5 6
6 1
3 7
7 8
8 3
10 1 10 1 2 2 2 2
Sample Output 2
28
Sample Explanation 2
The best solution is now to first invest in the company that owns offices in the cities 3, 7, 8, then invest in the company that owns offices at 1, 5, 6.
Sample Input 3
6 7 3 5
1 2
2 3
1 3
3 4
4 5
3 5
5 6
10 10 10 10 10 1
Sample Output 3
55
Sample Explanation 3
The best solution is to invest in the company that owns offices in the cities 1, 2. Then, invest in the company that owns offices in the cities 3, 4, 5. Finally, keep the last
Comments