One Goal
Time limit2sMemory limit512 MB
Given a tree of n cities and k friends, sum the smallest optimal meeting city over all n^k placements of the friends, modulo 998244353.
- Level
Hard9 of 10
- Topics
- Combinatorics, Tree, Math, Dynamic programming
- Solved
- No attempts yet
Problem
There are cities and roads in the Republic of Never. The cities are numbered from 1 to . Every road connects two cities and can be traversed in both directions. Any two cities can reach each other using the roads. The distance is the smallest number of roads needed to travel from city to city .
There are friends who want to meet. The -th friend lives in city . The friends choose city such that is minimum. If several cities achieve this minimum, they choose the one with the smallest number.
You do not know where the friends live. Each friend may live in any of the cities, so there are possible cases. Find the sum of the numbers of the cities the friends choose over all cases. Print the sum modulo 998244353.
Input
The first line contains two integers and (). Each of the following lines contains two integers and (, ), the numbers of the cities connected by the -th road. It is guaranteed that any two cities can reach each other using the roads.
Output
Print the sum of the numbers of the chosen cities over all cases, modulo 998244353.
Hint
In the first example, there are 3 cities and 2 friends, so there are cases. In three of them, both friends live in the same city, and they choose that city. In the other six, the friends live in different cities, and they choose city 1. The total is .