题目描述
Problem Description
Yamamoto-kun invented a device called PackDrop to verify the operation of applications in a network with poor communication conditions. PackDrop discards packets with a probability of $ 0.01 $.
Yamamoto-kun needs to install some PackDrops in a network consisting of $ N $ devices to meet the following conditions, while using the fewest PackDrops possible.
Each device in the network is numbered from $ 0 $ to $ N - 1 $.
Each device, except device $ 0 $, has one parent device. The parent device of device $ i $ is device $ P_i $. A device $ i $ viewed from device $ P_i $ is called a child device.
Devices with a direct parent-child relationship can be connected directly or via a series of PackDrops.
When a parent device and a child device are connected via $ n $ PackDrops, the packet delivery rate from the parent device to the child device is $ 0.99^n $. That is, when connected directly, the packet delivery rate is $ 1 $.
When the packet delivery rate from device $ x $ to device $ y $ is $ p $ and from device $ y $ to device $ z $ is $ q $, the packet delivery rate from device $ x $ to device $ z $ is $p \times q$.
PackDrop is the only factor that affects the packet delivery rate; no other factors change it.
There are $ M $ devices without child devices, and their numbers are $B_0, B_1, \ldots, B_{M-1}$. For each $ i $ ( $0 \leq i \leq N-1$ ), Yamamoto-kun wants the packet delivery rate from device $ 0 $ to device $ B_i $ to be $ 0.99^{C_i} $. Determine the minimum number of PackDrops required.
Input Format
The input is given from the standard input in the following format:
$ N $ $ M $ $ P_1 $ : $ P_{N-1} $ $ B_0 $ $ C_0 $ : $ B_{M-1} $ $ C_{M-1} $
Output Format
Output the minimum number of PackDrops.
Sample Input and Output
Sample Input #1
3 2
0
0
1 5
2 10
Sample Output #1
15
Sample Input #2
5 3
0
1
0
1
2 5
3 3
4 7
Sample Output #2
10
Sample Input #3
7 4
0
0
2
2
3
3
1 3
4 2
5 8
6 6
Sample Output #3
11
Notes/Hints
Constraints
- $2 \leq N \leq 1000$
- $1 \leq M \leq N - 1$
- $0 \leq P_i \leq i - 1$
- $1 \leq B_i \leq N - 1$
- $1 \leq C_i \leq 100000$
- $B_i \neq B_j$ if $i \neq j$
- There does not exist $ i, j $ such that $ P_i = B_j $
- If an integer $ k $ ( $1 \leq k \leq N-1$ ) is not in $P_1, P_2, \ldots, P_{N-1}$, then $ k $ is in $B_0, B_1, \ldots, B_{M-1}$
- $ N, M, P_i, B_i, C_i $ are integers
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分