求挑错,不是新人,也不是才学oi

P1546 [USACO3.1] 最短网络 Agri-Net

@[druoye_](/space/show?uid=97261) 1. 加边加错了 2. find函数写的很…… AC代码: ```cpp #include<bits/stdc++.h> using namespace std; int n,mapp[101][101],f[40000],k,tot,ans; struct edge{long int u,v,w;}; edge e[20001]; inline int find(int x){return f[x]==x? x:f[x]=find(f[x]);} inline bool cmp(edge a,edge b){return a.w<b.w;} inline void ready(){ cin>>n; for(int i=1;i<=n;i++) f[i]=i; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) cin>>mapp[i][j]; for(int i=1;i<=n;++i) for(int j=i;j<=n;++j){ e[++tot].u=i;e[tot].v=j;e[tot].w=mapp[i][j]; } } int main(){ ready(); sort(e+1,e+tot+1,cmp); for(int i=1;i<=tot;i++){ if(find(e[i].u)!=find(e[i].v)){ f[find(e[i].u)]=find(e[i].v); ans+=e[i].w;k++; if(k==n-1) break; } } cout<<ans; return 0; } ```
by superMB @ 2019-05-16 19:58:17


@[superMB](/space/show?uid=118265) **谢谢大佬!!!**
by druoye_ @ 2019-05-16 20:20:21


|