16分,请大佬看看这哪里错了

P1194 买礼物

给你改了下,过了 ```cpp #include <bits/stdc++.h> using namespace std; int n,m,cnt=0,sum=0,tot=1; struct edge { int from,to,val; bool operator <(const edge Com)const { return val<Com.val; } void getin(int I,int J) { int x; scanf("%d" , &x); if(x) { from=I; to=J; val=x; } } }; edge ve[500*500+5]; int fa[501]; int fdx(int x) { if(fa[x]==x) return x; return fa[x]=fdx(fa[x]); } void unxy(int x,int y) { fa[fdx(x)]=fdx(y); } void work() { for(int i=1;i<=cnt&&tot<=m;i++) { if(fdx(ve[i].from)!=fdx(ve[i].to)) { ++tot; sum+=ve[i].val; unxy(ve[i].from,ve[i].to); } } } int main() { cin>>n>>m; for(int i=1;i<=m;i++) { for(int j=1;j<=m;j++) { ve[++cnt].getin(i,j); } } for(int i=1;i<=m;i++) { ve[i].from=0; ve[i].to=i; ve[i].val=n; } for(int i=1;i<=m;i++) { fa[i]=i; } sort(ve+1,ve+cnt+1); work(); printf("%d",sum); return 0; } ```
by Vegetableless @ 2023-08-22 15:45:59


@[caojiaming](/user/775551)
by Vegetableless @ 2023-08-22 15:50:10


|