Walking Through the Tree
Time limit1sMemory limit1024 MB
Count the cyclic orders of all N tree vertices where no middle vertex lies on the tree path between its two neighbors, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Jong-gyeong, the PD of the current affairs and culture program 'Walking Through the Tree', wants to film each of countries exactly once. The countries are numbered from 1 to . There are two-way direct flights connecting pairs of countries, and every country can reach every other country by plane. When moving from one country to another, you may only use flights, and you must move so that the number of flights taken is minimized.
Jong-gyeong wants to choose the filming order carefully to raise ratings. For this, the order of the countries must additionally satisfy the following condition.
- For every with , (where and )
Here, is the minimum number of flights needed to travel from country to country .
Find the number of valid orders of the countries, modulo .
Input
The first line contains the number of countries .
From the second line through the -th line, the -th line contains two integers and separated by a space. This means the -th flight is a two-way direct flight connecting country and country .
Output
Print the answer on the first line.
Constraints
- ()
- Every country can reach every other country by plane.