Problem Statement
Let S(n) be the set of directed graphs with n vertices labeled from 0 to n-1 such that there is exactly one outgoing edge from each vertex. Self-loops are allowed. Therefore, we have |S(n)| = nn.
Given such a graph, a twirl is an operation that takes three distinct vertices labeled A, B, C and relabels them B, C, A. For example, if you choose the vertices labeled 4, 2, and 77, the following three things will happen simultaneously:
- The label of the first chosen vertex will change from 4 to 2.
- The label of the second chosen vertex will change from 2 to 77.
- The label of the third chosen vertex will change from 77 to 4.
Two graphs are called trisomorphic if we can transform one into the other by performing a sequence of zero or more twirls.
You are given an
Definition
- Class:
- Trisomorphism
- Method:
- maxSubset
- Parameters:
- int
- Returns:
- int
- Method signature:
- int maxSubset(int n)
- (be sure your method is public)
Notes
- The number 998244353 is a prime number.
Constraints
- n will be between 1 and 50, inclusive.
Examples
2
Returns: 4
It's impossible to pick three distinct vertices when n = 2. Thus, no two graphs are trisomophic.
3
Returns: 11
5
Returns: 67
13
Returns: 188742
42
Returns: 441900824
Don't forget about the modulo.
1
Returns: 1
4
Returns: 28
6
Returns: 175
7
Returns: 454
8
Returns: 1227
9
Returns: 3281
10
Returns: 8936
11
Returns: 24508
12
Returns: 67909
14
Returns: 528123
15
Returns: 1484116
16
Returns: 4188913
17
Returns: 11862010
18
Returns: 33702530
19
Returns: 96021326
20
Returns: 274274951
21
Returns: 785177942
22
Returns: 255861624
23
Returns: 483315537
24
Returns: 663653653
25
Returns: 805189296
26
Returns: 320839602
27
Returns: 904809730
28
Returns: 856997678
29
Returns: 890909494
30
Returns: 653194069
31
Returns: 992733388
32
Returns: 210032541
33
Returns: 992705617
34
Returns: 686723910
35
Returns: 357938868
36
Returns: 364964412
37
Returns: 651649626
38
Returns: 574425112
39
Returns: 266182583
40
Returns: 177310497
41
Returns: 124780056
43
Returns: 645025037
44
Returns: 617422487
45
Returns: 8554626
46
Returns: 196654294
47
Returns: 961051825
48
Returns: 317309493
49
Returns: 24040314
50
Returns: 449689257