Under construction

Still being built. Things may change

Walking Through the Tree

Time limit1sMemory limit1024 MB

Summary
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 NN countries exactly once. The countries are numbered from 1 to NN. There are N−1N-1 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 A[0]→A[1]→⋯→A[N−1]A[0] \rightarrow A[1] \rightarrow \cdots \rightarrow A[N-1] of the NN countries must additionally satisfy the following condition.

  • For every ii with 0≤i<N0 \le i < N, dist(A[i],A[i+1])+dist(A[i+1],A[i+2])≠dist(A[i],A[i+2])\text{dist}(A[i], A[i+1]) + \text{dist}(A[i+1], A[i+2]) \neq \text{dist}(A[i], A[i+2]) (where A[N]=A[0]A[N] = A[0] and A[N+1]=A[1]A[N+1] = A[1])

Here, dist(x,y)\text{dist}(x, y) is the minimum number of flights needed to travel from country xx to country yy.

Find the number of valid orders of the countries, modulo 998 244 353998\,244\,353.

Input

The first line contains the number of countries NN.

From the second line through the NN-th line, the (i+1)(i+1)-th line contains two integers xix_i and yiy_i separated by a space. This means the ii-th flight is a two-way direct flight connecting country xix_i and country yiy_i.

Output

Print the answer on the first line.

Constraints

  • 3≤N≤3003 \leq N \leq 300
  • 1≤xi,yi≤N1 \leq x_i, y_i \leq N (1≤i<N1 \leq i < N)
  • Every country can reach every other country by plane.

Examples1

  1. Example 1

    Input
    4
    1 2
    2 3
    3 4
    
    Expected output
    8