Codeforces Round 758 (Div.1 + Div. 2)
G
Alphabetic Tree
Codeforces
3500
原题
← F→
翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

The $i$-th of the following $n-1$ lines contains two integers $u_i, v_i$ and a lowercase Latin letter $c_i$ ($1 \le u_i, v_i \le n$, $u_i \neq v_i$), denoting the edge between nodes $u_i, v_i$ with a character $c_i$ 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 $10^5$.

翻译中…

Then $q$ lines follow, each containing four integers $u$, $v$, $l$ and $r$ ($1 \le u,v \le n$, $u \neq v$, $1 \le l \le r \le m$), denoting the queries.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
2 5 3
1 2 a
aab
abab
aaa
b
a
2 1 1 5
1 2 1 3
2 1 3 5
Output #1
8
7
4
InputCopy OutputCopy
Input #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
Output #2
3
4
2
1
1
10
InputCopy OutputCopy
题目信息
题号
1608G
时间限制
3 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
哈希
后缀结构
字符串
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。