323. Aviamachinations
Time limit per test: 2.25
second(s)
Memory limit: 65536
kilobytes
input: standard
output: standard
Berland consists of
N towns as you probably already know. Berland also has
M domestic airlines. In fact all these airlines belong to Don Berlione. Don Berlione was forced to create a number of companies instead of just one by the Antimonopoly Committee.
The Antimonopoly Committee was disbanded as a result of a government crisis. So, Don Berlione decided to close all but one airline. Naturally, this company should have flights (possibly including stopovers) from any town of Berland to any other one. To be able to choose the airline satisfying the above requirement, Don Berlione decided to carry out a number of fake purchasesell operations. During a purchasesell operation a flight of one airline is passed under the control of another airline. A purchasesell operation is just a money transfer from one pocket to another. But still a special tax should be paid to the government for each operation.
So each flight is characterized by two towns it connects, the airline it belongs to and the tax amount that should be paid for a purchasesell operation.
Your task is to find
P — the minimum possible amount of money Don Berlione needs to spend to make it possible to leave only one airline carrying out flights (possibly with stopovers) from each town of Berland to any other. Also you need to suggest a plan of actions for Don Berlione.
Input
The first line of the input file contains three integer numbers
N,
M,
K (1 ≤ N ≤ 2000; 1 ≤ M ≤ 2000; 0 ≤ K ≤ 200000), where
N is the number of towns,
M is the number of airlines,
K is the number of flights. Each of the following
K lines contains the description of the flight given by four integer numbers
a_{i},
b_{i},
c_{i},
p_{i}, where
a_{i},
b_{i} (
a_{i} !=
b_{i}; 1≤
a_{i},
b_{i}≤
N) are the numbers of towns connected by the flight (towns are numbered from 1 to
N),
c_{i} (1≤
c_{i}≤
M) is the number of the airline owning the flight (airlines are numbered from 1 to
M),
p_{i} (1≤
p_{i}≤ 100000) is the tax amount required for the purchasesell operation of the flight. Originally all flights are planned in such a way that it is possible to get from each town to any other using flights of one or several airlines. There can be several flights between a pair of towns.
Output
Write the desired minimum amount of money
P to the first line of the output. After that write a pair of numbers
R and
Q to the same line, where
R is the index of an airline which should be chosen by Don and
Q is the number of purchasesell operations. Write the description of operations to the following
Q lines. Each operation should be characterized by a single integer number
idx_{j}, which means that the flight
idx_{j} should be sold to the company
R. If there are several solutions for the problem, choose any of them.
Example(s)
sample input

sample output

4 3 4
2 3 1 6
4 3 2 7
1 2 2 3
1 3 3 5

5 2 1
4
