CF1608G.Alphabetic Tree
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given m strings and a tree on n nodes. Each edge has some letter written on it.
You have to answer q queries. Each query is described by 4 integers u, v, l and r. The answer to the query is the total number of occurrences of str(u,v) in strings with indices from l to r. str(u,v) is defined as the string that is made by concatenating letters written on the edges on the shortest path from u to v (in order that they are traversed).
给你 m 个字符串和一棵包含 n 个节点的树。每条边上都写有一个字母。
你需要回答 q 个查询。每个查询由 4 个整数 u、v、l 和 r 描述。该查询的答案为:在下标范围为 l 到 r(含)的字符串中,字符串 str(u,v) 出现的总次数。其中,str(u,v) 定义为:从节点 u 到节点 v 的最短路径上,按遍历顺序依次拼接各边上的字母所构成的字符串。
输入格式
The first line of the input contains three integers n, m and q (2≤n≤105, 1≤m,q≤105).
The i-th of the following n−1 lines contains two integers ui,vi and a lowercase Latin letter ci (1≤ui,vi≤n, ui=vi), denoting the edge between nodes ui,vi with a character ci on it.
It's guaranteed that these edges form a tree.
The following m lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed 105.
Then q lines follow, each containing four integers u, v, l and r (1≤u,v≤n, u=v, 1≤l≤r≤m), denoting the queries.
输入的第一行包含三个整数 n、m 和 q(2≤n≤105,1≤m,q≤105)。
接下来的 n−1 行中,第 i 行包含两个整数 ui,vi 和一个小写拉丁字母 ci(1≤ui,vi≤n,ui=vi),表示节点 ui 与 vi 之间的一条边,其上标有字符 ci。
保证这些边构成一棵树。
接下来的 m 行每行包含一个由小写拉丁字母组成的字符串。所有这些字符串的总长度不超过 105。
随后是 q 行,每行包含四个整数 u、v、l 和 r(1≤u,v≤n,u=v,1≤l≤r≤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测评打分。不知道怎么写?