#P5590. 赛车游戏

赛车游戏

Description

Mr. R and his friends plan to play a racing game, but they were tricked by the experienced driver mocania into going to Mount Akina.

On Mount Akina, there are nn nodes and mm edges. Mr. R and his friends need to start from node 11 and drive to node nn. Each edge has an initial direction. The experienced driver mocania got the map of Mount Akina, but does not know how long each road is. Obviously, for fairness in the racing game, every path from 11 to nn should have the same total length. mocania thinks: “I will just assign each edge a length from 1...91...9. Anyway, the silly Mr. R will not be able to tell.”

However, mocania is not very good at math and does not know how to assign lengths to the edges, so he comes to ask you, an OI expert, for help.

Input Format

The first line contains two integers n,mn, m.

The next mm lines each contain two integers u,vu, v, indicating a directed edge from uu to vv.

Output Format

If there is no solution, or if there is no path from 11 to nn, output 1-1.

If there is a solution, output two numbers n,mn, m on the first line, the same as in the input file.

Then output mm lines. Each line contains three integers u,v,wu, v, w, meaning the length of the edge from uu to vv is set to ww, where ww is an integer in 191\sim 9. The order of all edges must be the same as in the problem statement.

10 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 10
10 10
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
1 10 9

Hint

Constraints

This problem uses Special Judge and Subtask.

Subtask #1 (3030 points): n10n \leq 10, m20m \leq 20.
Subtask #2 (3030 points): n100n \leq 100, m200m \leq 200.
Subtask #3 (4040 points): n1000n \leq 1000, m2000m \leq 2000.

It is guaranteed that there are no multiple edges or self-loops in the testdata.

Translated by ChatGPT 5