Infimum of Paths

아직 제출이 없습니다시간 제한8초메모리 제한256 MB

문제

On a directed graph, we use lex(p)lex(p) to denote the lexical weight of a path pp, where the path pp can be regarded as a sequence of consecutive edges. The lexical weight is defined by the recurrence relation

lex(\[])=0,lex(\[e_1,e_2,,e_n])=w(e_1)+lex(\[e_2,e_3,,e_n])10,lex(\[]) = 0, lex(\[e\_1, e\_2, \ldots, e\_n]) = \frac{w(e\_1) + lex(\[e\_2, e\_3, \ldots, e\_n])}{10}\text{,}

where w(e_1)w(e\_1) is the weight of edge e_1e\_1, which is an integer between 00 and 99, inclusive.

Given a directed graph, find the infimum of the lexical weights of all paths from node 00 to node 11. The infimum of a set of rational numbers is the greatest rational number that, if exists, is less than or equal to all elements in this set.

입력

The first line of the input gives the number of test cases, TT (1T1001 \le T \le 100). TT test cases follow.

For each case, the first line contains two integers, nn (2n20002 \le n \le 2000, n20000\sum{n} \le 20000) and mm (1m40001 \le m \le 4000, m40000\sum{m} \le 40000), where nn is the number of nodes and mm is the number of edges.

Then mm lines follow, each of which contains three integers uu, vv, ww (0u,v<n0 \le u, v < n, 0w90 \le w \le 9), indicating an edge from uu to vv of weight ww.

It is guaranteed that there exists at least one path from node 00 to node 11 for each test case.

출력

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 11), and y is the answer modulo (109+7)(10^9 + 7). More specifically, if the answer can be formed as an irreducible fraction AB\frac{A}{B}, then y will be (AB1)mod(109+7)(A \cdot B^{-1}) \bmod (10^9 + 7).

힌트

For the first sample, the path corresponding to the infimum is 02410 \to 2 \to 4 \to 1, so the answer is 0.3130.313.