Separating Enemies
시간 제한2초메모리 제한2048 MB
일렬로 놓인 집들 사이 도로를 끊는 비용과 서로 적대하는 집 쌍이 주어질 때, 적대하는 쌍이 모두 분리되도록 도로를 끊는 최소 비용을 구한다.
문제
In the town of Unity Avenue Peace Centre (UAPC), there are 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 th and th house is dollars. Your task is to tell the town council how much this destruction will cost.
입력
The first line of input contains an integer () representing the number of houses in UAPC. The second line of input contains integers (), where is the cost to destroy the portion of the road between the th and th house. The third line of input contains an integer (), the number of pairs of enemies. The following lines each contain two integers and (), indicating that the residents of houses and 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.