#Lutece1290. 赏树的天行廖
赏树的天行廖
Migrated from Lutece 1290 赏树的天行廖
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
神奇的电子科技大学长着一棵神奇的树。
这棵树一共有个节点,从号到号,每条边上有一个字符。
一日天行廖在校园内游历,见到这棵树,忽然想到了一个问题。
定义为从根节点到的路径所构成的字符串。
对于每个节点,天行廖想知道一个数,使得是的最长后缀。
Input
输入一个整数,接下来两行。
第一行个整数,,,表示的父亲
第二行个整数,,,表示向其父亲连的边上的字符。
输入保证对于所有,
Output
输出个数,
Samples
2
0 0
1 2
0 0
2
0 1
1 1
0 1
Resources
咦咦。。。