Euler's flat in Zurich P84723


Statement
 

pdf   zip

Recently, Gauss has moved to Zurich, and his friend Euler, who used to live in Switzerland, has offered him to move into his empty flat. However, Gauss has found that the flat is a complete mess, so he has to clean every single part of it.

Euler’s flat can be modeled as an undirected graph with nn vertices, one for each spot. The graph has mm edges, each joining two spots that are a distance \ell apart. In addition, kk spots contain a piece of furniture of weight ww. Note that the \ells and the wws may be different.

To clean every spot uu with furniture, Gauss needs to first clear uu, moving furnitures around in such a way that no two pieces are in the same spot at the same time. The effort to move a piece of weight ww along a distance \ell is just ww \cdot \ell. After cleaning uu, Gauss will move back all furniture to their original place before cleaning another spot. What is the minimum effort to leave each uu empty? (Do not count the effort to move the furniture back.)

Input

Input consists of several cases with only integer numbers. Every case begins with nn, mm and kk, followed by mm triples u,v,u, v, \ell denoting an edge between spots uu and vv of length \ell, followed by kk pairs u,wu, w meaning that the spot uu contains a piece of furniture of weight ww.

You can assume 2n21042 \le n \le 2 \cdot 10^4, 1m5n1 \le m \le 5n, and 0<k<n0 < k < n. Spots are numbered from 00 to n1n - 1. All \ells and wws are between 1 and 10510^5. The graph is connected, without loops or parallel edges. No spot contains more than one piece of furniture.

Output

For each case, and for each spot uu with furniture, in increasing order of uu, print the minimum effort to move the furniture to clean uu. Print a line with 10 dashes after every case.

Public test cases
  • Input

    3 3 2
    0 1 5  1 2 9  2 0 15
    1 4  2 7
    
    4 3 3
    0 1 20000  1 2 60000  2 3 80000
    0 50000  1 70000  2 80000
    
    6 7 3
    0 3 20  1 3 30  3 2 7  3 4 5
    2 5 21  4 5 3  2 4 15
    4 9  3 2  2 6
    

    Output

    1 : 20
    2 : 83
    ----------
    0 : 11600000000
    1 : 10600000000
    2 : 6400000000
    ----------
    2 : 79
    3 : 37
    4 : 27
    ----------
    
  • Information
    Author
    Gerard Orriols
    Language
    English
    Official solutions
    C++
    User solutions
    C++