Minimum Cost Roads | 프로그래밍의 벗 PivotOJ
PivotOJ

Minimum Cost Roads

시간 제한: 2000ms메모리 제한: 1024MB출처: CCC 2023 SeniorBOJ 28315

문제

As the newly elected mayor of Kitchener, Alanna's first job is to improve the city's road plan.

Kitchener's current road plan can be represented as a collection of NN intersections with MM roads, where the ii-th road has length lil_i meters, costs cic_i dollars per year to maintain, and connects intersections uiu_i and viv_i. To create a plan, Alanna must select some subset of the MM roads to keep and maintain, and that plan's cost is the sum of maintenance costs of all roads in that subset.

To lower the city's annual spending, Alanna would like to minimize the plan's cost. However, the city also requires that she minimizes travel distances between intersections and will reject any plan that does not conform to those rules. Formally, for any pair of intersections (i,j)(i, j), if there exists a path from ii to jj taking ll meters on the existing road plan, Alanna's plan must also include a path between those intersections that is at most ll meters.

입력

The first line contains the integers NN and MM.

Each of the next MM lines contains the integers uiu_i, viv_i, lil_i, and cic_i, meaning that there currently exists a road from intersection uiu_i to intersection viv_i with length lil_i and cost cic_i (1ui,viN,uivi)(1 \le u_i, v_i \le N, u_i \neq v_i).

출력

Output one integer, the minimum possible cost of a road plan that meets the requirements.

예제

예제 1

입력
5 7
1 2 15 1
2 4 9 9
5 2 5 6
4 5 4 4
4 3 3 7
1 3 2 7
1 4 2 1
출력
25
코드를 제출하려면 로그인하세요.