Pro.ID21638 TitleSee You in You Tube Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21638 AC0 Submit0 Ratio- 时间&空间限制描述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, vi ≤ N, ui ≠ vi, li > 0 ). The next line contains one positive integer Q ( Q ≤ 104 ). Then Q hues followed, each containing two positive numbers ai, wi ( 1 ≤ ai ≤ T, 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, vi ≤ N, ui ≠ vi, li > 0 ). The next line contains one positive integer Q ( Q ≤ 104 ). Then Q hues followed, each containing two positive numbers ai, wi ( 1 ≤ ai ≤ T, 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 Sample Output 3 Source 样例输入2 1 样例输出3 作者 |