问题 K: Circuit

内存限制:256 MB 时间限制:5 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:5 通过:2

题目描述

Now there is a directed graph G=(V,E) with n vertices and m 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.

输入格式

The first line of input is a positive integer T(T15) representing the number of test cases. Description of the test cases follows:

The first line of each test case contains two integers n and m (1n500,0mn×(n1))—— the number of the vertices and edges in the given graph.

Each of the next m lines contains two integers ui , vi and wi (1ui,vin,1wi10^9)meaning that there is a directed edge of length wi between vertex ui and vertex vi in the graph.

The data guarantees that there will be no more than 1010 groups with a value of n exceeding 100.

输出格式

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 998244353.Output -1 -1 if there is no circuit.

输入样例 复制

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

输出样例 复制

7 2
-1 -1
8 4