CF917E.Upside Down

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn vertices, numbered from 11 through nn . There's a lowercase English letter written in each tunnel (edge).

Upside down is a magical world. There are mm types of monsters in upside down, numbered from 11 through mm . Each type of monster has a special word that gives them powers. The special word of type ii is sis_{i} . There are qq monsters in upside down. Each one is at a junction (vertex) and is going to some other junction. If monster of type kk goes from junction ii to junction jj , the power it gains is the number of times it sees its special world ( sks_{k} ) consecutively in the tunnels. More formally:

If f(i,j)f(i,j) is the string we get when we concatenate the letters written in the tunnels on the shortest path from ii to jj , then the power the monster gains is the number of occurrences of sks_{k} in f(i,j)f(i,j) .

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, n,mn,m and qq ( 2<=n<=1052<=n<=10^{5} , 1<=m,q<=1051<=m,q<=10^{5} ).

The next n1n-1 lines contain the tunnels (edges). Each line contains two integers vv and uu ( 1<=v,u<=n1<=v,u<=n , vuv≠u ) and a lowercase English letter cc , meaning there's a tunnel connecting junctions vv and uu written cc in it. It is guaranteed that the given graph is a tree.

The next mm lines contain the special words. ii -th line of them contains a single string sis_{i} ( 1<=si<=1051<=|s_{i}|<=10^{5} ), consisting of lowercase English letters. It is guaranteed that s1+s2+...+sm<=105|s_{1}|+|s_{2}|+...+|s_{m}|<=10^{5} ).

The next qq lines contain the monsters. Each line contains three integers ii , jj and kk ( 1<=i,j<=n1<=i,j<=n , iji≠j , 1<=k<=m1<=k<=m ), meaning a monster of type kk is going from junction number ii to junction number jj .

输出格式

Print qq lines. ii -th line should contain a single integer, the power the ii -th monster gains after moving.

输入输出样例

  • 输入#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

    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
    
首页