Logo
(追記) (追記ここまで)

31841번 - Nogcd 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB83302736.486%

문제

Boss, if $N≤30,円 000,ドル you should try to optimise the $N^2$ solution. (Friedrich Nietzsche)


Let $G$ be a undirected connected graph with $N$ nodes and $M$ edges. Label each of the $M$ edges with a distinct integer from 1ドル$ to $M$. For each node with degree greater than 1ドル,ドル the greatest common divisor of its incident edges' labels should be 1ドル$.

입력

The first line contains two integers $N$ and $M$.

The next $M$ lines contain two integers $u$ and $v,ドル representing two nodes that share an edge.

출력

Print $M$ lines, each containing three integers $u,ドル $v$ and $c$ corresponding to an edge with label $c$ between $u$ and $v$.

제한

  • 1ドル≤N≤10^5$
  • 1ドル≤M≤220,円 000$
  • There are no self-loops or multiple edges in the graph.

예제 입력 1

5 6
1 2
2 3
1 3
4 1
3 4
3 5

예제 출력 1

1 2 2
1 4 1
1 3 3
3 2 5
3 4 4
3 5 6

$G$ has 5ドル$ nodes and 6ドル$ edges.

The labels for node 1ドル$ are $\{2,1,3\}$.

The labels for node 2ドル$ are $\{2,5\}$.

The labels for node 3ドル$ are $\{3,4,5,6\}$.

The labels for node 4ドル$ are $\{1,4\}$.

Node 5ドル$ has degree 1ドル$.

힌트

출처

Olympiad > Romanian IOI Selection > Romanian IOI 2017 Selection #1 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /