。。。 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, &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)