#x1024. CF917E Upside Down
CF917E Upside Down
Upside Down
题面翻译
给出一棵 个节点的树,每一条边上有一个小写字母。
给定 个字符串 。
有 组询问,每组询问包含三个数:,表示如下询问:
以从 到 的路径上每一条边的字母连接起来所构成的字符串为文本串, 为模式串,求 在文本串中出现的次数。
题目描述
As we all know, Eleven has special abilities. Thus, Hopper convinced her to close the gate to the Upside Down World with her mind. Upside down monsters like to move between the worlds, so they are going to attack Hopper and Eleven in order to make them stop. The monsters live in the vines. The vines form a tree with vertices, numbered from through . There's a lowercase English letter written in each tunnel (edge).
Upside down is a magical world. There are types of monsters in upside down, numbered from through . Each type of monster has a special word that gives them powers. The special word of type is . There are monsters in upside down. Each one is at a junction (vertex) and is going to some other junction. If monster of type goes from junction to junction , the power it gains is the number of times it sees its special world ( ) consecutively in the tunnels. More formally:
If is the string we get when we concatenate the letters written in the tunnels on the shortest path from to , then the power the monster gains is the number of occurrences of in .
Hopper and Eleven want to get prepared, so for each monster, they want to know the power the monster gains after moving.
输入格式
The first line of input contains three integers, and ( , ).
The next lines contain the tunnels (edges). Each line contains two integers and ( , ) and a lowercase English letter , meaning there's a tunnel connecting junctions and written in it. It is guaranteed that the given graph is a tree.
The next lines contain the special words. -th line of them contains a single string ( ), consisting of lowercase English letters. It is guaranteed that ).
The next lines contain the monsters. Each line contains three integers , and ( , , ), meaning a monster of type is going from junction number to junction number .
输出格式
Print lines. -th line should contain a single integer, the power the -th monster gains after moving.
样例 #1
样例输入 #1
6 4 5
1 6 b
2 3 a
1 2 b
5 3 b
4 5 b
a
b
bb
aa
1 2 1
6 2 3
1 6 2
4 5 4
1 6 2
样例输出 #1
0
1
1
0
1
样例 #2
样例输入 #2
10 6 7
1 3 s
10 1 d
2 6 s
5 2 d
7 4 l
8 9 d
8 10 l
7 2 d
8 7 l
dl
dssld
d
d
l
sl
4 5 4
3 7 5
10 6 2
3 1 4
7 5 6
10 9 4
9 8 4
样例输出 #2
2
2
0
0
0
1
1