#P3109. [USACO14OPEN] Code Breaking G

    ID: 2148 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2014USACO枚举,暴力哈希,HASH前缀和

[USACO14OPEN] Code Breaking G

Description

The cows keep getting in trouble by taking rides on Farmer John's tractor, so he has hidden the keys to the tractor in a fancy new safe in his office. Undeterred, the cows have vowed to try and break into this safe.

The safe is protected by a rather complicated passcode system. The passcode entry system is arranged as a rooted tree of NN (1N20,000)(1 \leq N \leq 20,000) nodes, each of which requires a digit between 00 and 99. The nodes are indexed 0N10 \dots N-1.

The only information that the cows have is that certain sequences of length 55 do not occur along particular paths upwards through the tree.

Given MM (1M50,000)(1 \leq M \leq 50,000) length-55 sequences, together with their starting nodes in the tree, help the cows figure out how many passcodes have been ruled out. You should compute your answer modulo 12345671234567.

Input Format

Line 11: Two space-separated integers, NN and MM.

Lines 2N2\dots N: Line i+1i+1 contains a single integer p(i)p(i), denoting the parent of node i in the tree (0p(i)<i)(0 \leq p(i) < i).

Lines N+1N+MN+1\dots N+M: Line N+iN+i describes the ith sequence known not to occur in the code. The line will contain v(i)v(i) and s(i)s(i) separated by a space, where v(i)v(i) is the starting node of the sequence, and s(i)s(i) is a 55-digit string known not to occur starting at v(i)v(i) and proceeding upward in the tree. It is guaranteed that the root is at least 44 steps upward from v(i)v(i).

Output Format

Line 11: A single integer giving the number of ruled-out configurations,modulo 12345671234567.

6 2 
0 
1 
2 
3 
3 
4 01234 
5 91234 

19