Minimizing the cost of a graph P36054


Statement
 

pdf   zip

Consider a connected, undirected multigraph GG with labels at the edges. Define the cost of GG as the sum of its labels. You must compute the minimum cost cc that can be obtained after removing zero or more edges without disconnecting GG. Among all the solutions that achieve cost cc, you must also compute the minimum number of remaining edges mm, and the maximum number of remaining edges MM.

For instance, consider these two graphs:

image

The minimum possible cost of the first graph is 8, and there is just one way to achieve it, namely removing one of its seven edges: the 1–2 edge. Thus c=8c = 8, m=M=6m = M = 6. As for the second graph, it is easy to see that c=6c = -6, m=2m = 2, and M=4M = 4.

Input

Input is all integers, and consists of several descriptions of connected multigraphs. Every description starts with the number of vertices nn and the number of edges ee. Then follow ee triples, one for every edge, with its two vertices and its label in this order. The vertices are numbered from 0 to n1n - 1. Assume 0n100000 \le n \le 10000.

Output

For every given graph, output cc, mm and MM in one line.

Public test cases
  • Input

    6 7
    0 1 3   0 2 5   1 2 7   2 3 15
    4 5 -7      3 4 -5      3 5 -3
    
    2 4
    1 0 0
    0 0 0
    0 1 -3
    1 0 -3
    

    Output

    8 6 6
    -6 2 4
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C C++