Hotel Assignment
Time limit2sMemory limit1024 MB
Given a tree of N hotels, choose K distinct hotels so that the sum of pairwise distances among them is maximized.
- Level
Medium6 of 10
- Topics
- Tree, Dynamic programming
- Solved
- No attempts yet
Problem
The village of 경곽 has hotels and roads. Each road connects two distinct hotels, and any two hotels can reach each other using only roads, so the village forms a tree. The distance between two distinct hotels is the minimum number of roads that must be crossed to travel from one to the other.
One day, students from Gyeonggi Science High School came to 경곽 for a school trip. The students do not get along, so Seongho, the chief organizer of the trip, wants to assign the students to distinct hotels. To keep the students as far apart as possible, he wants to maximize the sum of distances over every pair of the assigned hotels.
Specifically, let be the distance between the hotel assigned to student and the hotel assigned to student . You must maximize . Help Seongho find the maximum value of this sum.
Input
The first line contains two integers and .
The next lines each contain two integers and , the numbers of the hotels connected by a road.
Output
Print the answer on the first line.
Constraints
- The village forms a tree.