21638_SeeYouinYouTube

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

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

Pro.ID

21638

Title

See You in You Tube

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Ling and Janice are good friends since childhood. Despite their deep friendship, they are eager to compete with each other in every aspect, from study to sports, from divination to having dreams. Some day, they fall in love with the same boy and get involved in a fierce (also boring team game against each other.

    On the first few rounds, Ling's team takes a 3 to 1 lead. This night, both teams come to a cemetery and start a new round, to distribute pies to ghost. Janice realizes she must win this round, or she will be beaten by Ling. There are N tombs in the cemetery, which are numbered from 1 to N. Both teams are at tomb 1. There are some tunnels connecting pairs of tombs, allowing one to climb from one end to the other. Each team should go to every tomb to leave some pies.

    It's risky to climb in the tunnel, so Janice wants to minimize the total length of the tunnels which they will go through. Unfortunately, Ling is well trained for Chinese Qigong, and she has the amazing capability to shorten one tunnel at a time. Janice is confused after that. So she turns to you, a member of her team, to let her know the minimum total length every time something is changed.

    输入

    There are multiple test cases. Each case start with a line containing two positive integers, N ( N ≤ 104 ) and T ( T ≤ 105 ), indicating the number of tombs and number of tunnels. T lines followed, each contains three numbers ui, vi and li, indicating that there is a tunnel of length li connecting tomb ui and vi ( 1 ≤ ui, viN, uivi, li > 0 ). The next line contains one positive integer Q ( Q ≤ 104 ). Then Q hues followed, each containing two positive numbers ai, wi ( 1 ≤ aiT, wi > 0 ), means that the length of the ai-th tunnel in the input become wi, where wi will be strictly less then the tunnel's current length. The test data guarantees that all the tombs can be reached from tomb number 1. No two tunnels connect same pair of tombs. The total length of all the tunnels fits in a 32-bit unsigned integer. Input is terminated by N=0 and T=0.

    输出

    Description

    Ling and Janice are good friends since childhood. Despite their deep friendship, they are eager to compete with each other in every aspect, from study to sports, from divination to having dreams. Some day, they fall in love with the same boy and get involved in a fierce (also boring team game against each other.

    On the first few rounds, Ling's team takes a 3 to 1 lead. This night, both teams come to a cemetery and start a new round, to distribute pies to ghost. Janice realizes she must win this round, or she will be beaten by Ling. There are N tombs in the cemetery, which are numbered from 1 to N. Both teams are at tomb 1. There are some tunnels connecting pairs of tombs, allowing one to climb from one end to the other. Each team should go to every tomb to leave some pies.

    It's risky to climb in the tunnel, so Janice wants to minimize the total length of the tunnels which they will go through. Unfortunately, Ling is well trained for Chinese Qigong, and she has the amazing capability to shorten one tunnel at a time. Janice is confused after that. So she turns to you, a member of her team, to let her know the minimum total length every time something is changed.

    Input

    There are multiple test cases. Each case start with a line containing two positive integers, N ( N ≤ 104 ) and T ( T ≤ 105 ), indicating the number of tombs and number of tunnels. T lines followed, each contains three numbers ui, vi and li, indicating that there is a tunnel of length li connecting tomb ui and vi ( 1 ≤ ui, viN, uivi, li > 0 ). The next line contains one positive integer Q ( Q ≤ 104 ). Then Q hues followed, each containing two positive numbers ai, wi ( 1 ≤ aiT, wi > 0 ), means that the length of the ai-th tunnel in the input become wi, where wi will be strictly less then the tunnel's current length. The test data guarantees that all the tombs can be reached from tomb number 1. No two tunnels connect same pair of tombs. The total length of all the tunnels fits in a 32-bit unsigned integer. Input is terminated by N=0 and T=0.

    Output

    For each test case, first output a line containing the minimum total length of the tunnels to be use. Then for each time Ling using her Qigong, output a line to update the value. Output one empty line after each test case.

    Sample Input

    2 1
    1 2 3
    1
    1 1
    5 6
    1 2 5
    2 3 3
    1 4 11
    2 4 6
    3 5 9
    4 5 12
    3
    3 3
    2 1
    6 8
    0 0

    Sample Output

    3
    1

    23
    20
    18
    17

    Source

    样例输入

    2 1
    1 2 3
    1
    1 1
    5 6
    1 2 5
    2 3 3
    1 4 11
    2 4 6
    3 5 9
    4 5 12
    3
    3 3
    2 1
    6 8
    0 0

    样例输出

    3
    1

    23
    20
    18
    17

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部