The Pentagon's computer network consists of computers, some of which are directly connected by bidirectional communication channels. To enhance security, the number of these channels has been minimized under the condition that any two computers can communicate, either directly or indirectly via other computers in the network.
The Central Bureau of Investigation wants to intercept all messages transmitted in the Pentagon's network. To accomplish this, renowned programmers have developed a virus which, once installed on a computer, relays all information passing through it to the Central Bureau. The cost of installing the virus varies for each computer. Your task is to determine a set of computers to infect, so that all communications can be intercepted, while minimizing the total installation cost.
The first line contains a single integer (1 \leq N \leq 500), the number of computers in the network.
In the next lines, the -th line lists the numbers of computers that are directly connected to computer .
The last line contains integers, each in the range , where the -th number is the cost of installing the virus on the -th computer.
Print the minimum possible total installation cost.
Example 1