A12140 | Moonwalk challenge
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Since astronauts from BubbleCup XI mission finished their mission on the Moon and are big fans of famous singer, they decided to spend some fun time before returning to the Earth and hence created a so called "Moonwalk challenge" game.
Teams of astronauts are given the map of craters on the Moon and direct bidirectional paths from some craters to others that are safe for "Moonwalking". Each of those direct paths is colored in one color and there is unique path between each two craters. Goal of the game is to find two craters such that given array of colors appears most times as continuous subarray on the path between those two craters (overlapping appearances should be counted).
To help your favorite team win, you should make a program that, given the map, answers the queries of the following type: For two craters and array of colors answer how many times given array appears as continuous subarray on the path from the first crater to the second.
Colors are represented as lowercase English alphabet letters.
Teams of astronauts are given the map of craters on the Moon and direct bidirectional paths from some craters to others that are safe for "Moonwalking". Each of those direct paths is colored in one color and there is unique path between each two craters. Goal of the game is to find two craters such that given array of colors appears most times as continuous subarray on the path between those two craters (overlapping appearances should be counted).
To help your favorite team win, you should make a program that, given the map, answers the queries of the following type: For two craters and array of colors answer how many times given array appears as continuous subarray on the path from the first crater to the second.
Colors are represented as lowercase English alphabet letters.
输入格式
In the first line, integer $N$ $(2 \leq N \leq 10^5)$ — number of craters on the Moon. Craters are numerated with numbers $1$ to $N$ .
In next $N-1$ lines, three values $u, v, L$ $(1 \leq u, v \leq N, L \in \{a, ..., z\})$ — denoting that there is a direct path with color $L$ between craters $u$ and $v$ .
Next line contains integer $Q$ $(1 \leq Q \leq 10^5)$ — number of queries.
Next $Q$ lines contain three values $u, v$ $(1 \leq u, v \leq N)$ and $S$ $(|S| \leq 100)$ , where $u$ and $v$ are the two cratersfor which you should find how many times array of colors $S$ (represented as string) appears on the path from $u$ to $v$ .
In next $N-1$ lines, three values $u, v, L$ $(1 \leq u, v \leq N, L \in \{a, ..., z\})$ — denoting that there is a direct path with color $L$ between craters $u$ and $v$ .
Next line contains integer $Q$ $(1 \leq Q \leq 10^5)$ — number of queries.
Next $Q$ lines contain three values $u, v$ $(1 \leq u, v \leq N)$ and $S$ $(|S| \leq 100)$ , where $u$ and $v$ are the two cratersfor which you should find how many times array of colors $S$ (represented as string) appears on the path from $u$ to $v$ .
输出格式
For each query output one number that represents number of occurrences of array S on the path from $u$ to $v$ .
输入输出样例
输入 #1
6 2 3 g 3 4 n 5 3 o 6 1 n 1 2 d 7 1 6 n 6 4 dg 6 4 n 2 5 og 1 2 d 6 5 go 2 3 g
输出 #1
1 1 2 0 1 1 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted