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

33673번 - Separating Enemies 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB157777.778%

문제

In the town of Unity Avenue Peace Centre (UAPC), there are $N$ houses all on the same side of a single road. There is a single citizen living in each house. Some pairs of citizens are enemies, and are prone to fighting if they can reach each other’s house via the road.

To prevent these fights, the town council has decided to destroy portions of the road between certain houses. The goal is to ensure that no pair of enemies can reach each other, while minimizing the cost of destruction. The cost to destroy the portion of the road between the $i$th and $(i+1)$th house is $c_i$ dollars. Your task is to tell the town council how much this destruction will cost.

입력

The first line of input contains an integer $N$ (1ドル≤N≤10^5$) representing the number of houses in UAPC. The second line of input contains $N-1$ integers $c_1,c_2,\dots ,c_{N-1}$ (1ドル≤c_i≤10^4$), where $c_i$ is the cost to destroy the portion of the road between the $i$th and $(i+1)$th house. The third line of input contains an integer $M$ (1ドル≤M≤10^5$), the number of pairs of enemies. The following $M$ lines each contain two integers $u$ and $v$ (1ドル≤u<v≤N$), indicating that the residents of houses $u$ and $v$ are enemies.

출력

Output a single integer representing the minimum total cost required to destroy portions of the road to ensure that each pair of enemies are separated.

제한

예제 입력 1

5
1 2 3 4
1
1 5

예제 출력 1

1

예제 입력 2

5
1 2 3 4
2
1 2
2 5

예제 출력 2

3

예제 입력 3

5
1 2 3 4
2
1 3
2 5

예제 출력 3

2

힌트

출처

University > University of Alberta Programming Contest > UAPC 2025 > Division 1 L번

  • 문제를 만든 사람: Ian DeHaan
(追記) (追記ここまで)

출처

대학교 대회

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

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