Nogcd

시간 제한1초메모리 제한1024 MB

요약
연결 그래프의 각 간선에 1부터 M까지 서로 다른 정수를 붙이되, 차수가 1보다 큰 모든 정점에서 이웃 간선 레이블의 최대공약수가 1이 되게 하라.
난이도

어려움10점 중 8점

유형
수학, 정수론, 그래프, 그리디
정답자
아직 제출이 없습니다

문제

Boss, if N≤30,000N≤30\\, 000, you should try to optimise the N2N^2 solution. (Friedrich Nietzsche)


Let GG be a undirected connected graph with NN nodes and MM edges. Label each of the MM edges with a distinct integer from 11 to MM. For each node with degree greater than 11, the greatest common divisor of its incident edges' labels should be 11.

입력

The first line contains two integers NN and MM.

The next MM lines contain two integers uu and vv, representing two nodes that share an edge.

출력

Print MM lines, each containing three integers uu, vv and cc corresponding to an edge with label cc between uu and vv.

제한

  • 1≤N≤1051≤N≤10^5
  • 1≤M≤220,0001≤M≤220\\, 000
  • There are no self-loops or multiple edges in the graph.

예제1

  1. 예제 1

    입력
    5 6
    1 2
    2 3
    1 3
    4 1
    3 4
    3 5
    
    예상 출력
    1 2 2
    1 4 1
    1 3 3
    3 2 5
    3 4 4
    3 5 6