Gusagwa City
Time limit3sMemory limit512 MB
Given a tree of N vertices, count the ways to place two teleport booths (possibly on the same vertex) so that the maximum pairwise travel distance is at most X.
- Level
Medium7 of 10
- Topics
- Tree, Shortest path, Brute force
- Solved
- No attempts yet
문제
Gusagwa City can be represented as a tree with vertices. The vertices are numbered from 0 to , and for every , vertex is connected to vertex by an edge. Moving along an edge from one vertex to another takes 1 minute.
The citizens of Gusagwa City decided to install teleport devices to reduce travel time. A teleport device has two identical booths, and each booth must be placed on a vertex. When you enter one booth, you immediately come out of the other booth. Both booths may be placed on the same vertex.
The distance between two vertices is the minimum time needed to travel from one to the other. Given , the edges, and an integer , let be the maximum distance over all pairs of vertices. Count the number of ways to install the teleport device so that does not exceed .
입력
The first line contains two integers and . The second line contains integers .
출력
Print the number of ways to install the teleport device so that does not exceed .
제한
- ()