#P9839. Circuit
Circuit
Circuit
Problem Description
Now there is a directed graph with vertices and edges (the graph does not guarantee connectivity). You need to calculate the length of the circuit with the smallest length. At the same time, on this basis you also need to count the number of the circuit with the smallest length. There are no multiedges and self-loops in the graph.
Input
The first line of input is a positive integer representing the number of test cases. Description of the test cases follows: The first line of each test case contains two integers and —— the number of the vertices and edges in the given graph. Each of the next lines contains two integers , and meaning that there is a directed edge of length between vertex and vertex in the graph. The data guarantees that there will be no more than groups with a value of exceeding .
Output
For each case, output two integers representing the length and the number of the circuit with the smallest length. Since the number may be large, you need to output the result of modulating the answer to .Output -1 -1 if there is no circuit.
Sample Input
3
3 4
1 2 4
2 1 3
2 3 2
3 1 1
2 1
1 2 1
5 7
1 2 4
2 1 4
1 3 1
3 4 1
4 2 2
2 5 2
5 1 2
Sample Output
7 2
-1 -1
8 4
Source
2023“钉耙编程”中国大学生算法设计超级联赛(4)