Broken Minimum Spanning Tree

아직 제출이 없습니다시간 제한1초메모리 제한2048 MB

문제

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 nn (2n2,0002 \le n \le 2\\,000) and mm (n1m3,000n-1 \le m \le 3\\,000), where nn is the number of nodes in the graph and mm is the number of edges in the graph. The nodes are numbered from 11 to nn.

Each of the next mm lines contains three integers uu, vv (1u,vn,uv1 \le u,v \le n, u \ne v), and ww (1w1091 \le w \le 10^9), signifying an edge connecting nodes uu and vv with weight ww. The edges are numbered from 11 to mm.

It is guaranteed that the graph is connected. The first n1n-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 kk, which is the minimum number of edge swaps needed to make the spanning tree a minimum spanning tree. Then output kk lines, each with two integers aa and bb, where aa is the number of the edge to remove and bb is the number of the edge to add. If there are multiple sets of kk edge swaps that work, any one will be accepted.