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

16025번 - Maximum Strategic Savings 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB44191846.154%

문제

A long time ago in a galaxy far, far away, there are N planets numbered from 1 to N. Each planet has M cities numbered from 1 to M. Let city f of planet e be denoted as (e, f).

There are N × P two-way flights in the galaxy. For every planet e (1 ≤ e ≤ N), there are P flights numbered from 1 to P. Flight i connects cities (e, ai) and (e, bi) and costs ci energy daily to maintain.

There are M × Q two-way portals in the galaxy. For all cities with number f (1 ≤ f ≤ M), there are Q portals numbered from 1 to Q. Portal j connects cities (xj, f) and (yj, f) and costs zj energy daily to maintain.

It is possible to travel between any two cities in the galaxy using only flights and/or portals.

Hard times have fallen on the galaxy. It was decided that some flights and/or portals should be shut down to save as much energy as possible, but it should remain possible to travel between any two cities afterwards.

What is the maximum sum of energy that can be saved daily?

입력

The first line contains four space-separated integers N, M, P, Q (1 ≤ N, M, P, Q ≤ 105).

Then P lines follow; the i-th one contains three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ M, 1 ≤ ci ≤ 108).

Then Q lines follow; the j-th one contains three space-separated integers xj, yj, zj (1 ≤ xj, yj ≤ N, 1 ≤ zj ≤ 108).

It is guaranteed that it will be possible to travel between any two cities using flights and/or portals. There may be multiple flights/portals between the same pair of cities or a flight/portal between a city and itself.

출력

Output a single integer, the maximum sum of energy that can be saved daily.

제한

예제 입력 1

2 2 1 2
1 2 1
2 1 1
2 1 1

예제 출력 1

3

예제 입력 2

2 3 4 1
2 3 5
3 2 7
1 2 6
1 1 8
2 1 5

예제 출력 2

41

One possible way is to shut down the flights between cities (1, 1) and (1, 1), (2, 1) and (2, 1), (1, 1) and (1, 2), (1, 3) and (1, 2), (2, 3) and (2, 2), and shut down the portal between cities (2, 3) and (1, 3) for total energy savings of 8 +たす 8 +たす 6 +たす 7 +たす 7 +たす 5 = 41.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2018 > CCC 2018 Senior Division 5번

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

출처

대학교 대회

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

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