atcoder#AGC059C. [AGC059C] Guessing Permutation for as Long as Possible
[AGC059C] Guessing Permutation for as Long as Possible
Score : points
Problem Statement
A teacher has a hidden permutation of . You are going to determine it.
To do this, you prepared a sequence of pairs of integers $(A_1,B_1),(A_2,B_2),\ldots,(A_{N(N-1)/2},B_{N(N-1)/2})$; this is a permutation of all pairs of the form (). Now, you will go over the pairs from the beginning. For a pair , you will ask if $P_{A_i}, and the teacher will tell you the answer. However, you will skip this question if you can already determine the answer to it from previous answers.
Find the number of permutations , for which with your algorithm you will have to ask all questions, modulo .
Constraints
- ()
- All values in the input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2
1 2
2
Clearly, for any permutation , you need to ask question.
4
1 2
1 3
2 3
2 4
3 4
1 4
4
Consider as an example. In this case, you will skip the third question since you know and from previous questions and you can determine . Therefore, should not be counted.
5
1 2
2 3
3 4
4 5
1 5
1 3
2 4
3 5
1 4
2 5
0