Superfast Transport

0

0 votes
Hard, Algorithms, Approved
Problem

Welcome to the future!

There are N communication junctions on Mars, and K cities, each located at its own junction. Junctions are numbered from 1 to N, and a city is denoted as its junction number.

Company StarZ, the first one exploring Mars, wants to build a superfast transporting system, called SuperPipe, on Mars. They are already using that system on Earth and its by far the most efficient way to travel between distant places.

Now, city with number i is willing to pay for being connected to the SuperPipe system, not only because it’s extremely profitable for its people, but also highly prestigeous. Moreover, there are M pairs of junctions that can be connected by a line of SuperPipe, and it’s known that if all M lines are built, then it is possible to travel between any two junctions with a SuperPipe. However, connecting two junctions with a line of SuperPipe is not cheap. For each of M possible lines, StarZ knows the cost of building that line.

As a computer scientist in StarZ research lab, your task is to maximize the profit of building a SuperPipe network. The profit is defined as a sum of amount of money that cities connected to the network pay minus the sum of costs of building all the lines in the network. The only requirement is that the network has to be connected, i.e. it is possible to travel between any two junctions in the network.

Input format

In the first line, there are three space separated integer N, M and K, denoting the number of junctions, the number of possible pairs of junctions to be connected with a SuperPipe line, and the number of cities. In the second line, there are N space separated integers , where denotes the amount of money that will be earned by including the i-th junction in the network. Notice that exactly K of these integers are positive and they denote junctions with cities. Then M lines follow. In the i-th of them there are three space-separated integers , , and denotes that junctions and can be connected by a SuperPipe line with cost .

Output format

In the first line, print two space separated integers X and Y, denoting respectively the number of junctions and the number of lines in the SuperPipe network. In the second line, print X space-separated integers denoting junctions in the network. After that, output Y lines, and in each of them print two space-separated integers denoting the pair of junctions in the network connected by a line.

Constraints






Scoring

For a single test file its absolute score is the profit of the returned network. If the output for a particular test file is invalid then this score is 0. Formally, for V and E denoting respectively the set of junctions and the set of lines in the returned network, and denoting the cost of building line e, the profit of such network is defined as:

The total absolute score of a submission is the sum of absolute scores across all test files. In this problem, scoring is set to relative, which means that the final score for a problem is your absolute score divided by the score of the best solution submitted by any participant. The objective is to maximize the total absolute score.

After the contest, new test files will be generated with the same method described below, and all submissions will be rejudged on these new test files.

Test generation

  • M is generated uniformly at random from range
  • K is generated uniformly at random from one of ranges: , , , and all these ranges are used equal number of times among test files
  • M pairs of junctions that can be connected by a line are generated using this graph generation method
  • K non-zero values of are generated uniformly at random from a range , and these K junctions, denoting the cities, are also chosen uniformly at random from all N junctions
  • Each cost of building a line between two junctions is generated uniformly at random from a range
Sample Input
4 4 2
2 0 0 2
1 2 1
2 3 1
3 4 1
1 4 1
Sample Output
2 1
1 4
1 4
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

If we take only one city to the network, either 1 or 4, and build no lines of SuperPipe, then the score will be 2 as the profit from this only city.

If we take both cities, 1 and 4, we have to connect them be lines of SuperPipe, because the final network must be connected. There are two ways to do that: either we take build line: , and , or we build only line . In the first case, the score is , while in the second case the score is , so 3 is the best we can do, and the sample output described exactly this network.

Editor Image

?