Ramen Delivery
Time limit1sMemory limit1024 MB
Given a tree rooted at room 1, sum over every K-subset of rooms the minimum walk time from room 1 that visits all of them, modulo 10^9+7.
- Level
Medium7 of 10
- Topics
- Tree, DFS, Combinatorics
- Solved
- No attempts yet
Problem
The dormitory of Seoul Science High School can be represented as a tree with rooms and corridors, where each corridor connects two different rooms. Every corridor can be traveled in both directions, and you can move between any two rooms through the corridors. Passing through one corridor takes unit of time.
Mingyu wants to make instant ramen for friends. Mingyu is currently in room , and Mingyu and all of the friends are in different rooms.
To do this, Mingyu will deliver hot water to every friend. Hot water is available only from the dispenser in room . Mingyu has a very large thermos, so one fill is enough to supply every friend.
Cooking ramen is risky. If the dormitory supervisor catches it, Mingyu can receive demerit points. To reduce the risk, Mingyu will visit the rooms so that the time at which the last hot water is delivered is as early as possible.
The way Mingyu visits the rooms is described below.
- Before receiving water, Mingyu checks in advance the rooms where the friends are.
- Mingyu gets water in room at time and sets out. Mingyu visits the rooms in a way that minimizes the time at which the friend who receives the last hot water gets it.
- Only the time Mingyu spends walking through corridors is counted. The time to hand out water and the time to fill it at the dispenser are ignored. The time Mingyu takes to return to his own room after giving out all the water is also ignored.
Before checking which rooms the friends are in, Mingyu wants to predict how long the delivery will take. For each of the ways to choose the rooms where the friends are, add up the time at which the last hot water is delivered.
Input
The first line contains the number of rooms and the number of friends , separated by a space.
From the second line through the th line, the th line contains the numbers and of the two rooms connected by corridor , separated by a space.
Output
Print the sum of the times at which the last hot water is delivered over all ways to choose the rooms of the friends, modulo .
Constraints
- The input is guaranteed to describe a tree.