Steiner tree in random graph
시간 제한2초메모리 제한1024 MB
무작위 가중 그래프에서 처음 n-k개 정점을 모두 포함하는 최소 가중 연결 부분 그래프를 찾아 간선을 출력한다.
문제
You are given a weighted graph on vertices. You should find a connected subgraph of minimal weight, which contains all vet rices with numbers from to .
To make problem easier to solve, and tests easier to generate, all tests are generated using following algorithm:
- Integers , , are chosen.
- All possible edges are shuffled in random order
- Next edge is added to graph if after it is add, it's possible to add some more edges to make graph connected with edges total.
- For each edge weight is generated uniformly on segment independent from other edges.
입력
In first line there are three integers (), (), (). On next lines there are triples of integers (, ), each of them means, that vertices и are connected by edge of weight .
It's guaranteed, that graph have no loops, multiple edges, and in all tests, except samples it's generated by algorithm described above.
출력
In first line, print one integer --- number of edges in chosen subgraph. In next lines print chosen edges.