문제
Problem 3: Code Breaking [Jacob Steinhardt, 2014]
For instance, suppose the tree is the following (rooted at A):
A <- B <- C <- D <- E
^
|
F
4 <- 3 <- 2 <- 1 <- *
^
|
0
4 <- 3 <- 2 <- 1 <- 9
^
|
*
which gives 19 once we account for the fact that
4 <- 3 <- 2 <- 1 <- 9
^
|
0
입력
* Line 1:
Two space-separated integers, N and M.
* Lines 2..N:
Line i+1 contains a single integer p(i), denoting the parent of node i in the tree (0 <= p(i) < i).
* Lines N+1..N+M:
Line N+i describes the ith sequence known not to occur in the code. The line will contain v(i) and s(i) separated by a space, where v(i) is the starting node of the sequence, and s(i) is a 5-digit string known not to occur starting at v(i) and proceeding upward in the tree. It is guaranteed that the root is at least 4 steps upward from v(i).
출력
* Line 1:
A single integer giving the number of ruled-out configurations, modulo 1234567.
예제1
6 2
0
1
2
3
3
4 01234
5 91234
19