Nyoj cabling problem (minimum spanning tree)

Source: Internet
Author: User

。。。 is destined to do water problems.

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <string>6#include <queue>7#include <algorithm>8#include <map>9#include <iomanip>Ten#include <climits> One#include <string.h> A#include <cmath> -#include <stdlib.h> -#include <vector> the#include <stack> -#include <Set> - using namespacestd; - #defineINF 1000000007 + #defineMAXN 4010 - #defineMod 1000007 + #defineN 100010 A #defineNN 30 at #defineSigma_size 3 - Const intMAX =1000100; - Const intMAXN = 6e5 +Ten; - using namespacestd; -typedefLong LongLL; -  in intvalue[555]; - intfa[555]; to structnode{ +     intu, V, c; -     BOOL operator< (ConstNode A)Const{ the         returnC <A.C; *     } $}a[255* -];Panax Notoginseng  -  the intT; + intN, M; A intans; the  + intFindset (intx) - { $     if(Fa[x] <0)returnx; $     returnFA[X] =Findset (fa[x]); - } - intMain () the { -CIN >>T;Wuyi      while(t--) { theAns =0; -Memset (A,0,sizeof(a)); Wumemset (Value,0,sizeof(value)); -memset (fa,-1,sizeof(FA)); AboutCIN >> N >>m; $          for(inti =0; I < m; ++i) { -scanf"%d%d%d", &a[i].u, &AMP;A[I].V, &a[i].c); -         } -          for(inti =1; I <= N; ++i) Ascanf"%d",&value[i]); +Sort (A, A +m); theSort (value +1, Value + N +1); -          for(inti =0; I < m; ++i) { $             intx =Findset (a[i].u); the             inty =Findset (A[I].V); the             if(X! =y) { theAns + =a[i].c; theFA[X] + =Fa[y]; -Fa[y] =x; in             } the         } theprintf"%d\n", ans+value[1]); About     } the     //System ("pause"); the     return 0; the}

Nyoj cabling problem (minimum spanning tree)

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.