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

0K<N3×103

1ui,viN

Subtask 1 [25%]

1N20

Subtask 2 [25%]

1N100

Subtask 3 [25%]

1N500

Subtask 4 [25%]

No additional constraints.

Input Specification

The first line contains 2 integers N and K.

The next N1 lines each contain 2 integers ui and vi, 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 998244352.

Sample Input 1

Copy
4 2
1 2
3 1
2 4

Sample Output 1

Copy
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

Copy
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

Copy
315531008

Explanation for Sample 2

Be sure to output your answer modulo 998244352.


Comments

There are no comments at the moment.