Salaj
Time limit2sMemory limit256 MB
For each edge count j up to MAX, count the valid connectivity history arrays on V vertices with j edges, modulo MOD.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Combinatorics, Graph
- Solved
- No attempts yet
Statement
Given two integers and , an array of length is a valid connectivity history array (CHA) if there is a directed graph with vertices and edges and a permutation of length such that, starting from an empty graph on vertices and adding edges in the order given by , every satisfies: after the -th edge is added, the number of strongly connected components is . The graph may not contain self-loops or multiple edges, but if the edge exists, the edge may also exist. For example, with and , is valid because the graph always has three strongly connected components, whatever the order. is valid because the graph added in that order has 3, 3, then 1 strongly connected components. is not valid, because no graph with three edges on three vertices has a edge order where the count drops after each added edge.
Input
The first line contains , the number of queries (). Each of the next lines contains three integers , , and (, , ).
Output
For each query, print one line with integers. The -th integer is the number of valid CHAs for the pair , taken modulo , where .