标签:panel mes font 程序 const height span int 成本
3 1 2 1 0 1 3 2 0 2 3 4 0 3 1 2 1 0 1 3 2 0 2 3 4 1 3 1 2 1 0 1 3 2 1 2 3 4 1 0
3 1 0
#include<iostream> #include<algorithm> using namespace std; int tree[101]; int findroot(int x){ if(tree[x]==-1) return x; else { int temp=findroot(tree[x]); tree[x]=temp; return temp; } } struct edge{ int a,b,cost,flag; bool operator < (const edge &A) const{ return cost<A.cost; } }edge[6000]; int main(){ int n; while(cin>>n){ if(n==0) break; for(int i=1;i<=n*(n-1)/2;i++){ cin>>edge[i].a>>edge[i].b>>edge[i].cost>>edge[i].flag; if(edge[i].flag==1) edge[i].cost=0; } for(int i=1;i<=n;i++){ tree[i]=-1; } int ans=0; sort(edge+1,edge+1+n*(n-1)/2); for(int i=1;i<=n*(n-1)/2;i++){ int a=findroot(edge[i].a); int b=findroot(edge[i].b); if(a!=b){ tree[a]=b; ans+=edge[i].cost; } } cout<<ans<<endl; } return 0; }
标签:panel mes font 程序 const height span int 成本
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736565.html