The JOI power plant has bases numbered from to . The bases are connected by wires. The -th wire connects the base and the base , in both directions. We can travel from any base to any other base by passing through some wires.
Each base of the JOI power plant has at most one power generator. Each power generator has a switch. In the beginning, the switch of every power generator is OFF
. You are the director of the JOI power plant. You may choose some power generators, and turn the switches of the chosen power generators to ON
. (It is allowed to choose nothing.) The power generators have the following properties.
- Assume that the bases have power generators. Moreover, assume that we can travel from the base to the base and from the base to the base , in this order, so that we do not pass through the same wire twice. If the switches of the power generators of the base and the base are
ON
, then the power generator of the base is broken. - A power generator will be activated if its switch is
ON
and it is not broken.
Finally, you will get rewards from activated power generators. You will get yen for each activated power generator. However, you will also have to pay repair expenses for broken power generators. You will have to pay yen for each broken power generator. The total amount of rewards minus the total amount of repair expenses will be your profit.
Write a program which, given the arrangement of the bases and the wires, and the information of power generators, calculates the maximum of your profit.
Input Specification
Read the following data from the standard input.
Here is a string of length representing the power generators of the bases. Each character of is either 0
or 1
. The -th character describes the power generator of the base . It is 0
if there is no power generator in the base . It is 1
if the base has a power generator.
Output Specification
Write one line to the standard output. The output should contain the maximum of your profit when you choose some power generators, and turn all the switches of the chosen power generators to ON
.
Constraints
- .
- .
- .
- .
- We can travel from any base to any other base by passing through some wires.
- is a string of length consisting of
0
,1
. - contains at least one
1
.
Subtasks
- (6 points) .
- (41 points) .
- (53 points) No additional constraints.
Sample Input 1
6
2 3
4 3
1 3
3 5
6 2
110011
Sample Output 1
3
Explanation for Sample 1
In this sample input, the bases have power generators.
If you turn the switches of the bases to ON
, the power generators of the bases will be activated, and you get yen. Since you will not pay repair expenses, your profit is yen. Since it is the maximum of your profit, output .
On the other hand, if you turn the switches of the bases to ON
, the power generator of the base will be broken, and the power generator of the bases will be activated. You will get yen, and you will pay yen for repair expenses. Therefore, your profit will be yen.
If you turn the switches of the bases to ON
, the power generator of the base will be broken, and the power generator of the bases will be activated. You will get yen, and pay yen for repair expenses. Therefore, your profit will be yen.
Sample Input 2
8
1 2
3 5
6 4
4 5
5 2
7 2
2 8
11111111
Sample Output 2
3
Sample Input 3
16
7 10
5 11
9 4
14 12
2 11
14 16
4 2
1 13
11 3
7 1
15 9
2 1
11 6
14 9
8 9
0111111001001110
Sample Output 3
5
Comments
Edit: nvm my solution is just bad