#P2323. [HNOI2006] 公路修建问题

    ID: 1292 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2006二分并查集各省省选湖南Special Judge生成树

[HNOI2006] 公路修建问题

Description

OI island is a very beautiful island, and since its development, many people have come to travel here. However, because the island has only recently been developed, its transportation system is still poor. Therefore, the OIER Association was founded to build the transportation system of OI island.

OI island has nn tourist attractions, labeled from 11 to nn. Now, the OIER Association needs to build roads to connect these attractions. A road connects two attractions. There are two types of roads, which we call Type 1 roads and Type 2 roads. Cars travel faster on Type 1 roads, but they cost more to build.

The OIER Association plans to build n1n-1 roads to connect all attractions (so that there is a path between any two attractions). To ensure the efficiency of the road system, the OIER Association wants at least kk (0kn10 \le k \le n-1) of these n1n-1 roads to be Type 1 roads. The OIER Association also does not want any single road to be too expensive. Therefore, under the above conditions, they want the cost of the most expensive road to be as small as possible. Your task is, given some candidate roads, to choose n1n-1 roads that satisfy the above conditions.

Input Format

  • The first line contains three numbers nn (1n100001 \le n \le 10000), kk (0kn10 \le k \le n-1), and mm (n1m20000n-1 \le m \le 20000), separated by spaces. Here nn and kk are as described above, and mm means there are mm pairs of attractions between which a road can be built.
  • The following m1m-1 lines each contain four positive integers a,b,c1,c2a, b, c_1, c_2 (1a,bn1 \le a, b \le n, aba \ne b, 1c2c1300001 \le c_2 \le c_1 \le 30000), indicating that a road can be built between attractions aa and bb. If a Type 1 road is built, the cost is c1c_1; if a Type 2 road is built, the cost is c2c_2.
  • In actual judging, there will be only m1m-1 road entries.

Output Format

  • The first line contains a single number, which is the cost of the most expensive road among the chosen roads.
  • The next n1n-1 lines each contain two positive integers tt and pp. Here tt and pp indicate that on the tt-th pair of attractions in the input (indexed from 11 in input order), a Type pp road is built.
  • The n1n-1 lines must be output in increasing order of tt. If multiple solutions achieve the minimal value of the maximum road cost, output any one of them.
4 2 5 
1 2 6 5
1 3 3 1
2 3 9 4
2 4 6 1
6 
1 1 
2 1 
4 1

Hint

Translated by ChatGPT 5