Hangzhou Electric 2988--dark Roads

Source: Internet
Author: User

Dark roads

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 798 Accepted Submission (s): 329


Problem descriptioneconomic times these days is tough, even in Byteland. To reduce the operating costs, the Government of Byteland have decided to optimize the road lighting. Till now every road is illuminated all night long, which costs 1 Bytelandian Dollar per meter and day. To save money, they decided to no longer illuminate every road, but to switch off the road lighting of some streets. To make sure this inhabitants of Byteland still feel safe, they want to optimize the lighting in such a-a, that afte R darkening some streets at night, there'll still be at least one illuminated path from every junction in Byteland to Ev ery other junction.

What's the maximum daily amount of money the government of Byteland can save, without making their inhabitants feel Unsaf E?

Inputthe input file contains several test cases. Each test case is starts with a numbers m and N, the number of junctions in Byteland and the number of roads in Byteland, R Espectively. Input is terminated by m=n=0. Otherwise, 1≤m≤200000 and m-1≤n≤200000. Then follow n integers triples x, y, z specifying that there'll be a bidirectional road between x and y with length Z met ERs (0≤x, y < M and x≠y). The graph specified by all test case is connected. The total length of any roads in each test case is less than 231.

Outputfor each test case, print one line containing the maximum daily amount the government can save.

Sample Input7 11 0 1 7 0 3 51 2 8 1 3 9 1 4 7 2 4 53 4 15 3 5 64 5 8 4 6 9 5 6 11 0 0

Sample Output51

source2009/2010 ULM Local Contest

Recommendlcy | We have carefully selected several similar problems for you:2985 2986 2992 2991 2990 RE: Start thinking more, row two order, road is road, just let you find Cost the least. Map[][]. , .
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 intfather[200200];8 intN, M;9 structrodeTen { One     intx, Y, W; A} num[200200], shu[200200]; -  - BOOLCMP (Rode X, rode y) the { -     returnX.W >Y.W; - } -  + BOOLCPM (Rode X, rode y) - { +     returnX.W <Y.W; A } at  - voidInit () - { -      for(inti =0; I < n; i++) -Father[i] =i; - } in  - intFindinta) to { +     if(A = =Father[a]) -         returnA; the     Else *         returnFather[a] =find (Father[a]); $ }Panax Notoginseng  - BOOLMercyintAintb) the { +     intQ =find (a); A     intp =find (b); the     if(Q! =p) +     { -FATHER[Q] =p; $         return true; $     } -     Else -         return false; the } - Wuyi intMain () the { -      while(~SCANF ("%d%d", &n, &m), n+m) Wu     { -Init ();intsum =0; About          for(inti =0; I < m; i++) $         { -scanf" %d%d%d", &num[i].x, &AMP;NUM[I].Y, &NUM[I].W); -shu[i].x = num[i].x; Shu[i].y = NUM[I].Y; SHU[I].W =NUM[I].W; -Sum + =NUM[I].W; A         } +         /*int sum = 0; the sort (num, num + M, CMP); - for (int i = 0; i < m; i++) $         { the if (Mercy (num[i].x, num[i].y)) the sum + = NUM[I].W; the         }*/ the         intTotal =0; -Sort (Shu, Shu +m, CPM); in          for(inti =0; I < m; i++) the         { the             if(Mercy (shu[i].x, shu[i].y)) AboutTotal + =SHU[I].W; the         }  theprintf"%d\n", ABS (Sum-Total )); the     } +     return 0; -}

Hangzhou Electric 2988--dark Roads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.