Byteland Railways encountered a necessity of restructuring and reduction of the rail network. After a deep analysis of of the rail network it has been decided which railway stations will be removed and which ones will stay. It has been also decided that the rail network should be reduced as far as possible. It remains to choose which railway lines should be removed and which ones should stay.
The rail network is composed of rail segments connecting railway stations. It is known that from each station one can travel to every other station (potentially visiting some intermediate stations). Rail segments are bidirectional. There can be at most one rail segment connecting each pair of stations. Each segment can be assigned a cost of maintenance, which is a positive integer. The rail segments that will remain should be chosen in such way that:
Write a programme which:
The first line of input contains two positive integers and , , (), separated by a single space. denotes the number of railway stations and is the number of rail segments. Railway stations are numbered from to . The following lines contain descriptions of the rail segments, one per line. Each of these lines contains three positive integers , and , , , . and are the numbers of stations that are connected by the segment and is its cost of maintenance. The 'th line contains a sequence of integers separated by single spaces. The first one of them is - the number of stations that should remain (, ). It is followed by the numbers of these stations in increasing order.
The first line of output should contain two integers and separated by a single space, where is the total cost of maintenance of the segments that should remain and is the number of these segments. Each of the following lines should contain two integers and , separated by a single space - the numbers of stations that are connected by the segment. The total cost of maintenance of the segments can be at most two times greater than the lowest achievable total cost.
For the input data:
8 11 1 2 6 3 1 5 2 3 8 3 4 9 3 5 10 5 4 3 5 6 9 6 4 8 6 8 8 6 7 7 8 7 10 4 2 5 7 8
the correct result is:
42 5 2 3 3 5 5 6 6 7 6 8
Task author: Marcin Kubica.