Tagged with: Usaco gold cheering up the cows minimum spanning tree
Test instructions: It can be understood to give you a diagram, let you build a tree, and then start from a root, each one side will consume the right side of the Edge + edge. Finally add a root to the point, and ask at least how much it cost.
The puzzle: Change the edge and make the minimum spanning tree.
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define N 101000#define inf 0x3f3f3f3fusing namespace std;struct ksd{int U,v,len;bool operator < (const KS D &a) Const{return Len<a.len;}} Road[n];int p[n];int n,m,ans=inf;int f[n];int Find (int x) {return x==f[x]?x:f[x]=find (f[x]);} int main () {int i,j,k;int a,b,c;scanf ("%d%d", &n,&m), for (i=1;i<=n;i++) {scanf ("%d", &p[i]); Ans=min (ans , P[i]); f[i]=i;} for (i=1;i<=m;i++) {scanf ("%d%d%d", &a,&b,&c); road[i].u=a,road[i].v=b,road[i].len=p[a]+p[b]+c*2;} Sort (road+1,road+m+1), for (i=1;i<=m;i++) {int Fa=find (ROAD[I].U), Fb=find (ROAD[I].V), if (FA!=FB) {ans+=road[i]. LEN;F[FB]=FA;}} printf ("%d\n", ans); return 0;}
Copy to Google TranslateTranslation Results
"Usaco" 2.Cheering up the cows minimum spanning tree,