CF1608G.Alphabetic Tree

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given mm strings and a tree on nn nodes. Each edge has some letter written on it.

You have to answer qq queries. Each query is described by 44 integers uu , vv , ll and rr . The answer to the query is the total number of occurrences of str(u,v)str(u,v) in strings with indices from ll to rr . str(u,v)str(u,v) is defined as the string that is made by concatenating letters written on the edges on the shortest path from uu to vv (in order that they are traversed).

输入格式

The first line of the input contains three integers nn , mm and qq ( 2n1052 \le n \le 10^5 , 1m,q1051 \le m,q \le 10^5 ).

The ii -th of the following n1n-1 lines contains two integers ui,viu_i, v_i and a lowercase Latin letter cic_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \neq v_i ), denoting the edge between nodes ui,viu_i, v_i with a character cic_i on it.

It's guaranteed that these edges form a tree.

The following mm lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed 10510^5 .

Then qq lines follow, each containing four integers uu , vv , ll and rr ( 1u,vn1 \le u,v \le n , uvu \neq v , 1lrm1 \le l \le r \le m ), denoting the queries.

输出格式

For each query print a single integer — the answer to the query.

输入输出样例

  • 输入#1

    2 5 3
    1 2 a
    aab
    abab
    aaa
    b
    a
    2 1 1 5
    1 2 1 3
    2 1 3 5

    输出#1

    8
    7
    4
  • 输入#2

    9 5 6
    1 2 a
    2 7 c
    1 3 b
    3 4 b
    4 6 b
    3 5 a
    5 8 b
    5 9 c
    ababa
    cabbb
    bac
    bbbac
    abacaba
    2 7 1 4
    2 5 1 5
    6 3 4 4
    6 9 4 5
    5 7 3 5
    5 3 1 5

    输出#2

    3
    4
    2
    1
    1
    10
首页