Logo
(追記) (追記ここまで)

28315번 - Minimum Cost Roads 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB52232044.444%

문제

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 $N$ intersections with $M$ roads, where the $i$-th road has length $l_i$ meters, costs $c_i$ dollars per year to maintain, and connects intersections $u_i$ and $v_i$. To create a plan, Alanna must select some subset of the $M$ 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),ドル if there exists a path from $i$ to $j$ taking $l$ meters on the existing road plan, Alanna's plan must also include a path between those intersections that is at most $l$ meters.

입력

The first line contains the integers $N$ and $M$.

Each of the next $M$ lines contains the integers $u_i,ドル $v_i,ドル $l_i,ドル and $c_i,ドル meaning that there currently exists a road from intersection $u_i$ to intersection $v_i$ with length $l_i$ and cost $c_i$ $(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ドル \le N, M \le 2,000円$
  • 0ドル \le l_i \le 10^9$
  • 1ドル \le c_i \le 10^9$

예제 입력 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

예제 출력 1

25

Here is a diagram of the intersections along with a valid road plan with minimum cost.

Each edge is labeled with a pair $(l, c)$ denoting that it has length $l$ meters and cost $c$ dollars. Additionally, the roads that are part of the plan are highlighted, with a total cost of 7ドル + 1 +たす 6 +たす 7 +たす 4 = 25$.

It can be shown that we cannot create a cheaper plan that also respects the city's requirements.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCC 2023 Senior Division 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /