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

28146번 - Broken Minimum Spanning Tree 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB286696430.476%

문제

Ethan was tasked with finding a minimum spanning tree of a weighted, connected, undirected graph. However, he misunderstood the task and found a spanning tree that may not be minimal. To make his spanning tree a minimum spanning tree, you perform a sequence of edge swaps. An edge swap removes one edge from the spanning tree and adds an edge from the graph which is not currently in the spanning tree. After each edge swap, the tree must still be a spanning tree. What is the minimum number of edge swaps you must perform to fix Ethan's minimum spanning tree?

입력

The first line of input contains two integers $n$ (2ドル \le n \le 2,000円$) and $m$ ($n-1 \le m \le 3,000円$), where $n$ is the number of nodes in the graph and $m$ is the number of edges in the graph. The nodes are numbered from 1ドル$ to $n$.

Each of the next $m$ lines contains three integers $u,ドル $v$ (1ドル \le u,v \le n, u \ne v$), and $w$ (1ドル \le w \le 10^9$), signifying an edge connecting nodes $u$ and $v$ with weight $w$. The edges are numbered from 1ドル$ to $m$.

It is guaranteed that the graph is connected. The first $n-1$ edges of the input are Ethan's initial spanning tree. The graph may not be simple; there can be multiple edges between the same pair of nodes.

출력

Output a single integer $k,ドル which is the minimum number of edge swaps needed to make the spanning tree a minimum spanning tree. Then output $k$ lines, each with two integers $a$ and $b,ドル where $a$ is the number of the edge to remove and $b$ is the number of the edge to add. If there are multiple sets of $k$ edge swaps that work, any one will be accepted.

제한

예제 입력 1

4 4
1 2 10
2 3 3
3 4 1
1 4 4

예제 출력 1

1
1 4

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2023 C번

  • 문제를 만든 사람: Arnav Sastry
(追記) (追記ここまで)

출처

대학교 대회

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

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