Wind Turbines

시간 제한4초메모리 제한2048 MB

요약
일부 터빈 구간이 해안과 무료로 연결될 때, 모든 터빈이 해안에 도달하도록 하는 최소 비용 간선 부분집합을 각 질의마다 구한다.
난이도

어려움10점 중 9점

유형
그래프, 최소 신장 트리, 유니온 파인드, 그리디
정답자
아직 제출이 없습니다

문제

Anna has been tasked with designing the wiring for a new offshore wind farm in the North Sea consisting of NN turbines, numbered 0,1,…,N−10, 1, \ldots, N-1. Her goal is to ensure that all turbines are connected to the shore as cheaply as possible.

Anna has a list of MM potential connections, each linking two wind turbines and having a specific cost. Additionally, the nearby city has agreed to cover the costs of connecting a consecutive interval \[ℓ,r]\[\ell, r] of turbines to the shore. That is, each turbine tt in this range (ℓ≤t≤r\ell\le t\le r) is directly connected to the shore for free. If all potential connections are built, there is a way to reach any wind turbine from any other wind turbine. That implies that as soon as one of the wind turbines is connected to the shore, it is possible to build connections such that the power from all the turbines can be transferred to the shore. Of course, more connections to the shore may allow for a cheaper total cost. Note that the free connections are the only direct ones to the shore.

It is Anna's job to select a subset of the potential connections in a way that minimizes the sum of their costs, while ensuring that every wind turbine can reach the shore (possibly via other wind turbines).

In order to make an informed decision, the city provides Anna with QQ possible options for the interval \[ℓ,r]\[\ell, r]. The city asks Anna to compute the minimum cost for each of these scenarios.

입력

The first line of the input contains three integers, NN, MM and QQ.

The following MM lines contain three integers each, u_iu\_i, v_iv\_i and c_ic\_i. The iith line describes a potential connection between wind turbines u_iu\_i and v_iv\_i that has the cost c_ic\_i. These connections are undirected and connect two different turbines. No two connections are between the same pair of turbines. It is guaranteed that, if all potential connections are built, any wind turbine is reachable from any other (directly or indirectly).

The next QQ lines contain two integers each, ℓ_i\ell\_i and r_ir\_i, describing the scenario where the shore directly connects to the wind turbines ℓ_i,ℓ_i+1,…,r_i\ell\_i,\ell\_i+1,\ldots,r\_i. Note that we can have r_i=ℓ_ir\_i = \ell\_i when the shore directly connects to a single wind turbine.

출력

Output QQ lines, one line per scenario, containing one integer each, the minimum cost of connecting the turbines such that every turbine can deliver its power to the shore.

제한

  • 2≤N≤100,0002 \le N\le 100\\,000.
  • 1≤M≤100,0001 \le M\le 100\\,000.
  • 1≤Q≤200,0001 \le Q\le 200\\,000.
  • 0≤u_i,v_i≤N−10 \le u\_i,v\_i \le N-1.
  • u_i≠v_iu\_i \ne v\_i, and there is at most one direct connection between each pair of wind turbines.
  • 1≤c_i≤1,000,000,0001 \le c\_i \le 1\\,000\\,000\\,000.
  • 0≤ℓ_i≤r_i≤N−10 \le \ell\_i\le r\_i \le N-1.

힌트

In the first example, we are given the following graph of potential connections.

We are given three scenarios. In the first scenario, turbine 1 is the only one with a connection to the shore. In this case, we need to keep all connections except for the connection between turbine 00 and turbine 22, giving a total cost of 2+3+6+3=142+3+6+3=14. In the next scenario, the turbines 3 and 4 are connected to the shore. In this case, we keep the connections (1,0)(1,0), (1,2)(1,2) and (2,4)(2,4), giving a cost of 8. In the third scenario, all but turbine 0 are connected to the shore. In this case, we only need to connect this one to another turbine, which we do by choosing the connection (0,1)(0,1). The solutions to the scenarios are depicted below:

The first and the sixth samples satisfy the constraints of test groups 2, 5 and 7. The second and the seventh samples satisfy the constraints of test groups 1, 2, 5 and 7. The third sample satisfies the constraints of test groups 2, 3, 5 and 7. The fourth sample satisfies the constraints of test groups 2, 4, 5 and 7. The fifth sample satisfies the constraints of test groups 2, 5, 6 and 7.

예제7

  1. 예제 1

    입력
    5 5 3
    1 0 2
    0 2 5
    1 2 3
    3 0 6
    2 4 3
    1 1
    3 4
    1 4
    
    예상 출력
    14
    8
    2
    
  2. 예제 2

    입력
    5 4 4
    0 1 3
    1 2 1
    2 3 5
    3 4 2
    0 4
    2 3
    2 4
    2 2
    
    예상 출력
    0
    6
    4
    11
    
  3. 예제 3

    입력
    7 7 4
    6 4 3
    1 4 5
    3 2 4
    0 3 2
    5 2 3
    4 0 1
    1 3 1
    0 1
    2 3
    4 5
    5 6
    
    예상 출력
    12
    10
    10
    10
    
  4. 예제 4

    입력
    7 7 3
    2 6 1
    1 0 1
    0 5 1
    1 2 2
    3 4 1
    5 3 1
    5 4 1
    5 6
    1 3
    3 4
    
    예상 출력
    5
    4
    6
    
  5. 예제 5

    입력
    7 7 4
    6 4 3
    1 4 5
    3 2 4
    0 3 2
    5 2 3
    4 0 1
    1 3 1
    0 3
    0 6
    0 1
    0 4
    
    예상 출력
    7
    0
    12
    6
    
  6. 예제 6

    입력
    9 13 4
    0 1 1
    2 0 3
    1 2 4
    5 4 4
    2 5 6
    3 1 7
    8 1 4
    6 3 9
    0 3 5
    3 5 3
    4 3 2
    6 2 4
    7 8 5
    1 8
    4 7
    6 7
    1 2
    
    예상 출력
    1
    14
    22
    2
    
  7. 예제 7

    입력
    6 5 1
    0 1 1000000000
    1 2 1000000000
    2 3 1000000000
    3 4 1000000000
    4 5 1000000000
    1 1
    
    예상 출력
    5000000000