21773_WateringHole

2022-5-16 18:20| 发布者: Hocassian| 查看: 30| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505833466400-Problem List-采集的数据-后羿采集器.html

Pro.ID

21773

Title

Watering Hole

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21773

AC

20

Submit

54

Ratio

37.04%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Farmer John has decided to bring water to his N (2 ≤ N ≤ 5,000) pastures which are conveniently numbered 1..N. And He has M (1 ≤ M ≤ 25,000) pipes. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe to another pasture which already has water.

    Digging a well in pasture i costs Wi (1 ≤ Wi ≤ 100,000). Connecting pastures i and j with a pipe costs p (1 ≤ p ≤ 100,000). Since the length and quality are different, there may be more than one pipes in different costs connecting pasture i and j.

    Luckily, farmer John found there was only one plan to minimize his cost.

    Farmer Jack, farmer John's friend, has P (1 ≤ P ≤ 1,000) pipes. He promised that he could give one pipe to Farmer John, and farmer John can use it to connect his pasture i and j. Now, farmer John wants to know how much the minimum amount he will have to pay to water all of his pastures if he chooses one more pipe from Jack.

    输入

    There are serveral cases:

    Line 1: Three integers: N, M and P

    Lines 2: N space-separated integers; the i-th integer is Wi

    Lines 3..M+3: Three integers: i, j, p. Means a pipe connecting pasture i and j costs p

    Lines M+4..P+M+4: Two Integers: i, j. Farmer Jack can give Farmer John a pipe connecting pasture i and j.

    输出

    Description

    Farmer John has decided to bring water to his N (2 ≤ N ≤ 5,000) pastures which are conveniently numbered 1..N. And He has M (1 ≤ M ≤ 25,000) pipes. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe to another pasture which already has water.

    Digging a well in pasture i costs Wi (1 ≤ Wi ≤ 100,000). Connecting pastures i and j with a pipe costs p (1 ≤ p ≤ 100,000). Since the length and quality are different, there may be more than one pipes in different costs connecting pasture i and j.

    Luckily, farmer John found there was only one plan to minimize his cost.

    Farmer Jack, farmer John's friend, has P (1 ≤ P ≤ 1,000) pipes. He promised that he could give one pipe to Farmer John, and farmer John can use it to connect his pasture i and j. Now, farmer John wants to know how much the minimum amount he will have to pay to water all of his pastures if he chooses one more pipe from Jack.

    Input

    There are serveral cases:

    Line 1: Three integers: N, M and P

    Lines 2: N space-separated integers; the i-th integer is Wi

    Lines 3..M+3: Three integers: i, j, p. Means a pipe connecting pasture i and j costs p

    Lines M+4..P+M+4: Two Integers: i, j. Farmer Jack can give Farmer John a pipe connecting pasture i and j.

    Output

    Line 1..P: A single integer denoting the minimum cost of providing all the pastures with water if farmer John chooses the i-th pipe from farmer Jack.

    Sample Input

    4 6 1
    5 4 4 3
    1 2 2
    1 3 2
    1 4 2
    2 3 3
    2 4 3
    3 4 4
    3 4

    Sample Output

    7

    Source

    样例输入

    4 6 1
    5 4 4 3
    1 2 2
    1 3 2
    1 4 2
    2 3 3
    2 4 3
    3 4 4
    3 4

    样例输出

    7

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部