#x1009. CF1608G Alphabetic Tree
CF1608G Alphabetic Tree
Alphabetic Tree
题面翻译
给定 个仅包含小写字母的字符串和一棵包含 个节点的树,树的每条边上都有一个小写字母。我们定义 为将在树上从 到 的路径上经过的所有边上的小写字母顺此拼接得到的字符串。你需要回答 次询问,每次询问给定 个整数 ,你需要回答在所有下标在 的字符串中, 出现了多少次。
数据范围:
- ,。
- ,,。
Translated by Eason_AC
题目描述
You are given strings and a tree on nodes. Each edge has some letter written on it.
You have to answer queries. Each query is described by integers , , and . The answer to the query is the total number of occurrences of in strings with indices from to . is defined as the string that is made by concatenating letters written on the edges on the shortest path from to (in order that they are traversed).
输入格式
The first line of the input contains three integers , and ( , ).
The -th of the following lines contains two integers and a lowercase Latin letter ( , ), denoting the edge between nodes with a character on it.
It's guaranteed that these edges form a tree.
The following lines contain the strings consisting of lowercase Latin letters. The total length of those strings does not exceed .
Then lines follow, each containing four integers , , and ( , , ), denoting the queries.
输出格式
For each query print a single integer — the answer to the query.
样例 #1
样例输入 #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
样例输入 #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