Jumping on a Tree
Time limit4sMemory limit512 MB
Given a tree and an integer d, count the groups of vertices that are linked by jumps between pairs exactly d edges apart.
- Level
Medium7 of 10
- Topics
- Tree, Union-find, DFS
- Solved
- No attempts yet
Problem
You are given a tree on vertices. Suppose we are at the vertex . In one step we can go from to any other vertex such that there are exactly edges on the shortest path between and . A vertex is reachable from if we can get to from using zero or more steps.
Naturally, all vertices can be divided into reachability classes. A reachability class is a set of vertices such that any vertex in is reachable from any other vertex in , but no vertex outside is reachable from any vertex in . How many reachability classes are there in the given tree?
Input
The first line contains two space-separated integers and (, ).
Next lines describe the edges of the tree. Each line contains two space-separated integers, the indices of the vertices connected by the edge. Indices are 1-based.
Output
Print one integer, the number of reachability classes.