Steiner tree in random graph

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

요약
무작위 가중 그래프에서 처음 n-k개 정점을 모두 포함하는 최소 가중 연결 부분 그래프를 찾아 간선을 출력한다.
난이도

어려움10점 중 8점

유형
그리디, 그래프, 최소 신장 트리, 수학
정답자
아직 제출이 없습니다

문제

You are given a weighted graph on nn vertices. You should find a connected subgraph of minimal weight, which contains all vet rices with numbers from 11 to n−kn - k.

To make problem easier to solve, and tests easier to generate, all tests are generated using following algorithm:

  • Integers nn, mm, kk are chosen.
  • All n⋅(n−1)2\frac{n\cdot(n-1)}{2} 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 mm edges total.
  • For each edge weight is generated uniformly on segment \[50,100]\[50, 100] independent from other edges.

입력

In first line there are three integers nn (5≤n≤1005 \le n \le 100), mm (2⋅n≤m≤10⋅n2\cdot n \le m \le 10\cdot n), kk (0≤k≤300 \le k \le 30). On next mm lines there are triples of integers a_ib_iw_ia\_i b\_i w\_i (1≤a_i<b_i≤n1 \le a\_i < b\_i \le n, 50≤w_i≤10050 \le w\_i \le 100), each of them means, that vertices a_ia\_i и b_ib\_i are connected by edge of weight w_iw\_i.

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 cc --- number of edges in chosen subgraph. In next cc lines print chosen edges.

예제2

  1. 예제 1

    입력
    5 10 3
    1 2 50
    1 3 51
    1 4 52
    1 5 53
    2 3 54
    2 4 55
    2 5 56
    3 4 57
    3 5 58
    4 5 59
    
    예상 출력
    1
    1 2
    
  2. 예제 2

    입력
    5 10 2
    1 2 100
    1 3 100
    1 4 57
    1 5 56
    2 3 100
    2 4 54
    2 5 53
    3 4 52
    3 5 51
    4 5 50
    
    예상 출력
    3
    5 2
    5 3
    1 5