CF1608G.Alphabetic Tree

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

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).

给你 mm 个字符串和一棵包含 nn 个节点的树。每条边上都写有一个字母。

你需要回答 qq 个查询。每个查询由 44 个整数 uu、vv、ll 和 rr 描述。该查询的答案为:在下标范围为 ll 到 rr(含)的字符串中,字符串 str(u,v)str(u,v) 出现的总次数。其中,str(u,v)str(u,v) 定义为:从节点 uu 到节点 vv 的最短路径上,按遍历顺序依次拼接各边上的字母所构成的字符串。

输入格式

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

The ii-th of the following n−1n-1 lines contains two integers ui,viu_i, v_i and a lowercase Latin letter cic_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_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 (1≤u,v≤n1 \le u,v \le n, u≠vu \neq v, 1≤l≤r≤m1 \le l \le r \le m), denoting the queries.

输入的第一行包含三个整数 nn、mm 和 qq(2≤n≤1052 \le n \le 10^5,1≤m,q≤1051 \le m,q \le 10^5)。

接下来的 n−1n-1 行中,第 ii 行包含两个整数 ui,viu_i, v_i 和一个小写拉丁字母 cic_i(1≤ui,vi≤n1 \le u_i, v_i \le n,ui≠viu_i \neq v_i),表示节点 uiu_i 与 viv_i 之间的一条边,其上标有字符 cic_i。

保证这些边构成一棵树。

接下来的 mm 行每行包含一个由小写拉丁字母组成的字符串。所有这些字符串的总长度不超过 10510^5。

随后是 qq 行,每行包含四个整数 uu、vv、ll 和 rr(1≤u,v≤n1 \le u,v \le n,u≠vu \neq v,1≤l≤r≤m1 \le l \le r \le m),表示查询。

输出格式

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

输入解题思路,AI测评打分。不知道怎么写?

首页