当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5041:Just A Challenge

题目描述
Matt receives a gift from his friend Bobo. It is a tree which has N vertices and (N - 1) edges with single character. Yes, it is the tree in computer science.

Matt denotes the number of edges between vertices a and b as d(a, b). The string obtained by concatenating all characters from a to b is defined as s(a, b).

Given string L and R of length M, Matt would like to know the number of (a, b) s.t.

● d(a, b) = M,
● L<=s(a, b)<=R.

where "<=" means lexicographical comparision.
输入解释
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

For each test case, the first line contains two integers N (2<=N<=10^5) and M (1<=M<N).

Each of the following (N - 1) lines contains ai, bi, ci denoting an edge between vertex ai and bi with character ci (1<=ai, bi<=n).The vertices are conveniently labled with 1, 2,……, n. ci is either 'a' or 'b'.

The last two lines contain string L and R (|L| = |R| = M, L<=R). L and R consist of 'a' and 'b'.
输出解释
For each test case, output one line "Case #x: y", where x is the case number (starting from 1), y is the number of (a, b).
输入样例
2
2 1
1 2 a
a
b
4 2
1 2 a
2 3 b
3 4 a
aa
ab
输出样例
Case #1: 2
Case #2: 2

提示
Please use  #pragma comment(linker, "/STACK:16777216")
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5041

最后修改于 2020-10-25T23:19:12+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 262144/262144K(Java/Others)