loneliness - ShinriiTin's Blog - 博主是sb
codeforces 455E Function
kangaroo

loneliness

ShinriiTin posted @ 2015年6月17日 18:03 in 未分类 with tags 某不科学的三千元系列 , 926 阅读

题意:

给出一棵以1为根的有向树,每个节点上有一个字符(只会是小写字母)。

多次询问,给出一个字符集合,要求统计树上合法的串的数量。

合法的串满足4个要求:

1.是树上某个点向根方向的走所形成的串

2.串中所有的字符来自给定的字符集合

3.给定的字符集合中的每一个字符都在串中出现过

4.没有被任意一个满足前三条条件的路径完全包含

树的节点数和询问次数均不超过105

 

分析:

如果一个路径合法的串,当且仅当该路径向两端延伸1个位置都不能有在路径出现的字符。

我们记录每个节点向根方向的最近的出现某个字符的节点,显然合法的串只可能出现在这条路径上。

再记录每个节点所有儿子的字符集合,对于每个节点按深度枚举要走到的字符,判断是否合法。

 

Avatar_small
Emma 说:
2023年1月24日 01:08

This interesting problem presents a unique challenge in which the user must count the number of legal strings on a directed tree, given a character set. The buy real estate Okatie strings must meet four distinct requirements for them to be considered legal. This task requires the user to have a keen understanding of the tree structure, as well as the character set provided. It's a great mental exercise, and it can be quite rewarding!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter