A9097 | Book of Evil
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains $n$ settlements numbered from 1 to $n$ . Moving through the swamp is very difficult, so people tramped exactly $n-1$ paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to reach any settlement from any other one by traversing one or several paths.
The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range $d$ . This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance $d$ or less from the settlement where the Book resides.
Manao has heard of $m$ settlements affected by the Book of Evil. Their numbers are $p_{1},p_{2},...,p_{m}$ . Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task.
The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range $d$ . This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance $d$ or less from the settlement where the Book resides.
Manao has heard of $m$ settlements affected by the Book of Evil. Their numbers are $p_{1},p_{2},...,p_{m}$ . Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task.
输入格式
The first line contains three space-separated integers $n$ , $m$ and $d$ ( $1<=m<=n<=100000; 0<=d<=n-1$ ). The second line contains $m$ distinct space-separated integers $p_{1},p_{2},...,p_{m}$ ( $1<=p_{i}<=n$ ). Then $n-1$ lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integers $a_{i}$ and $b_{i}$ representing the ends of this path.
输出格式
Print a single number — the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0.
输入输出样例
输入 #1
6 2 3 1 2 1 5 2 3 3 4 4 5 5 6
输出 #1
3
Sample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted