CF917E.Upside Down

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

As we all know, Eleven has special abilities. Thus, Hopper convinced her to close the gate to the Upside Down World with her mind. Upside down monsters like to move between the worlds, so they are going to attack Hopper and Eleven in order to make them stop. The monsters live in the vines. The vines form a tree with n vertices, numbered from 1 through n. There's a lowercase English letter written in each tunnel (edge).

Upside down is a magical world. There are m types of monsters in upside down, numbered from 1 through m. Each type of monster has a special word that gives them powers. The special word of type i is s__i. There are q monsters in upside down. Each one is at a junction (vertex) and is going to some other junction. If monster of type k goes from junction i to junction j, the power it gains is the number of times it sees its special world (s__k) consecutively in the tunnels. More formally:

If f(i, j) is the string we get when we concatenate the letters written in the tunnels on the shortest path from i to j, then the power the monster gains is the number of occurrences of s__k in f(i, j).

Hopper and Eleven want to get prepared, so for each monster, they want to know the power the monster gains after moving.

众所周知,十一拥有特殊能力。因此,霍珀说服她用意念关闭通往颠倒世界的传送门。颠倒世界的怪物喜欢在两个世界之间穿梭,因此它们将攻击霍珀和十一,以阻止他们关闭传送门。这些怪物栖息在藤蔓中。藤蔓构成一棵具有 nn 个顶点的树,顶点编号为 11 到 nn。每条隧道(即树的一条边)上都写有一个小写英文字母。

颠倒世界是一个魔法世界。其中共有 mm 种怪物,编号为 11 到 mm。每种怪物都拥有一个赋予其力量的特殊单词。第 ii 种怪物的特殊单词为 sis_i。颠倒世界中共有 qq 只怪物,每只怪物位于某个路口(即某个顶点),并计划前往另一个路口。若一只类型为 kk 的怪物从路口 ii 移动到路口 jj,则它获得的力量等于其特殊单词 sks_k 在所经隧道序列中连续出现的次数。更准确地说:

设 f(i, j)f(i,\,j) 表示从 ii 到 jj 的最短路径上所有隧道(边)所写字母按顺序拼接而成的字符串,则该怪物获得的力量即为 sks_k 在 f(i, j)f(i,\,j) 中作为子串出现的次数。

霍珀和十一希望提前做好准备,因此对于每只怪物,他们都想知道该怪物移动后所获得的力量值。

输入格式

The first line of input contains three integers, n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105).

The next n - 1 lines contain the tunnels (edges). Each line contains two integers v and u (1 ≤ v, u ≤ n, v ≠ u) and a lowercase English letter c, meaning there's a tunnel connecting junctions v and u written c in it. It is guaranteed that the given graph is a tree.

The next m lines contain the special words. i-th line of them contains a single string s__i (1 ≤ |s__i| ≤ 105), consisting of lowercase English letters. It is guaranteed that |_s_1| + |_s_2| + ... + |s__m| ≤ 105).

The next q lines contain the monsters. Each line contains three integers i, j and k (1 ≤ i, j ≤ n, i ≠ j, 1 ≤ k ≤ m), meaning a monster of type k is going from junction number i to junction number j.

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

接下来的 n−1n-1 行描述隧道(即树的边)。每行包含两个整数 vv 和 uu(1≤v,u≤n1 \leq v, u \leq n,v≠uv \neq u)以及一个小写英文字母 cc,表示在结点 vv 与 uu 之间存在一条标有字母 cc 的隧道。保证所给图是一棵树。

接下来的 mm 行描述特殊单词。其中第 ii 行包含一个字符串 sis_i(1≤∣si∣≤1051 \leq |s_i| \leq 10^5),仅由小写英文字母组成。保证 ∣s1∣+∣s2∣+⋯+∣sm∣≤105|s_1| + |s_2| + \dots + |s_m| \leq 10^5。

接下来的 qq 行描述怪物。每行包含三个整数 ii、jj 和 kk(1≤i,j≤n1 \leq i, j \leq n,i≠ji \neq j,1≤k≤m1 \leq k \leq m),表示一个类型为 kk 的怪物正从编号为 ii 的结点向编号为 jj 的结点移动。

输出格式

Print q lines. i-th line should contain a single integer, the power the i-th monster gains after moving.

输出 q 行。第 i 行应包含一个整数,表示第 i 个怪物移动后获得的力量值。

输入输出样例

  • 输入#1

    6 4 5
    1 6 b
    2 3 a
    1 2 b
    5 3 b
    4 5 b
    a
    b
    bb
    aa
    1 2 1
    6 2 3
    1 6 2
    4 5 4
    1 6 2

    输出#1

    0
    1
    1
    0
    1
  • 输入#2

    10 6 7
    1 3 s
    10 1 d
    2 6 s
    5 2 d
    7 4 l
    8 9 d
    8 10 l
    7 2 d
    8 7 l
    dl
    dssld
    d
    d
    l
    sl
    4 5 4
    3 7 5
    10 6 2
    3 1 4
    7 5 6
    10 9 4
    9 8 4

    输出#2

    2
    2
    0
    0
    0
    1
    1

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

首页