Power Plant
Time limit1sMemory limit512 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
The JOI power plant has bases numbered from 1 to . The bases are connected by wires. The -th wire () connects the base and the base , in both directions. You can travel from any base to any other base by passing through some wires.
Each base has at most one power generator, and each generator has a switch. At the beginning, the switch of every generator is OFF. You are the director of the plant. You may choose some generators and turn their switches ON. Choosing none is allowed. The generators have the following properties.
- Suppose bases , , and have generators, and you can travel from to and then from to without passing through the same wire twice. If the switches of the generators at and are ON, then the generator at is broken.
- A generator is activated if its switch is ON and it is not broken.
You get 1 yen for each activated generator. You pay 1 yen for each broken generator. Your profit is the total reward minus the total repair expense.
Write a program that, given the bases, the wires, and the generator information, computes the maximum profit.
Input
The first line contains . Each of the next lines contains and . The last line contains a string of length .
N
A_1 B_1
...
A_{N-1} B_{N-1}
S
The -th character of describes base . It is 0 if the base has no generator and 1 if it has one.
Output
Write one line to the standard output containing the maximum profit when you choose some generators and turn their switches ON.
Constraints
- .
- is a string of length consisting of
BandW. The characterBappears times in , and the characterWappears times in .