DMOPC '21 Contest 2 P5 - Permutations

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You are given a tree with N nodes, the i-th node initially having a value of i. In one operation, you may remove any edge from the tree after swapping the values of the two nodes it connects. How many possible permutations of values are there after performing exactly K operations?

Constraints

0 \le K < N \le 3 \times 10^3

1 \le u_i, v_i \le N

Subtask 1 [25%]

1 \le N \le 20

Subtask 2 [25%]

1 \le N \le 100

Subtask 3 [25%]

1 \le N \le 500

Subtask 4 [25%]

No additional constraints.

Input Specification

The first line contains 2 integers N and K.

The next N-1 lines each contain 2 integers u_i and v_i, denoting the endpoints of the i-th edge.

Output Specification

Output the number of possible permutations of values after performing exactly K operations. Since this value may be large, output it modulo 998\,244\,352.

Sample Input 1

4 2
1 2
3 1
2 4

Sample Output 1

5

Explanation for Sample 1

The five possible permutations are listed below as arrays, where the i-th element represents the value of the i-th node:

  • [2, 3, 1, 4]
  • [2, 4, 3, 1]
  • [3, 1, 2, 4]
  • [3, 4, 1, 2]
  • [4, 1, 3, 2]

Sample Input 2

20 15
9 3
2 4
10 20
1 19
7 20
15 16
11 19
17 16
5 19
16 20
4 17
13 11
6 20
14 17
12 19
18 19
8 3
19 16
3 15

Sample Output 2

315531008

Explanation for Sample 2

Be sure to output your answer modulo 998\,244\,352.


Comments

There are no comments at the moment.