#P6017. [CSGRound3] 仙人掌
[CSGRound3] 仙人掌
Description
ckw has many edge-cactus graphs. An edge-cactus graph is a simple undirected connected graph in which each edge belongs to at most one simple cycle.
ckw defines the degree sequence of an undirected graph. The length of the degree sequence is the number of vertices in the graph, and the -th element of the degree sequence is the degree of the vertex numbered .
ckw wants to know: among all edge-cactus graphs with vertices and edges, how many different degree sequences are there.
Output the answer modulo . (If no valid cactus exists, output .)
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case, one line contains two integers , representing the number of vertices and the number of edges.
Output Format
For each test case, output one integer per line, the answer modulo .
7
4 4
5 6
50 70
90 102
40 41
2000 1999
1785 2425
13
5
442759796
851878741
292277388
943337434
183253103
Hint
[Sample Explanation]
For the first test case, here are four valid degree sequences: .
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (8 points): .
- Subtask 2 (10 points): .
- Subtask 3 (18 points): .
- Subtask 4 (12 points): .
- Subtask 5 (8 points): .
- Subtask 6 (10 points): .
- Subtask 7 (16 points): .
- Subtask 8 (18 points): no special constraints.
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号