PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000041. Trò chơi đua xe (Racing Game)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trò chơi đua xe (Racing Game)

Racing Game

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

Assign an integer length between 11 and 99 to every directed edge, so that every walk from vertex 11 to vertex nn has the same total length. Walks may repeat vertices. Output -1 if there is no walk from 11 to nn or no valid assignment exists.

Input

First line n,mn,m, followed by mm ordered directed edges u,vu,v.

Output

Print -1, or print n,mn,m and then mm triples u,v,wu,v,w in their input order, with 1≤w≤91\le w\le9.

Subtasks

  • Subtask 1 (30 points): 2≤n≤102\le n\le10, 1≤m≤201\le m\le20; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; no repeated directed edge.
  • Subtask 2 (30 points): 2≤n≤1002\le n\le100, 1≤m≤2001\le m\le200; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; no repeated directed edge.
  • Subtask 3 (40 points): 2≤n≤10002\le n\le1000, 1≤m≤20001\le m\le2000; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; no repeated directed edge.

Examples

Input

3 3
1 2
2 3
1 3

Output

3 3
1 2 1
2 3 1
1 3 2

Explanation

There are two walks from 11 to 33: the direct edge and the two-edge route through 22. Assigning weights 1,1,21,1,2 gives both walks total length 22, while every edge length lies between 11 and 99.