求助。。。。T三个点RE一个点

P3366 【模板】最小生成树

第一次发讨论。。。还不太会用 这样我重发一下 ```cpp #include<algorithm> #include<cstdlib> #include<cstdio> using namespace std; struct apple{ int from,to,distance; bool operator < ( const apple & other) const { return distance<=other.distance ; } }; apple edge[200001]; int fa[5001]; int find(int xx) { if(fa[xx]==xx) return xx; if(fa[xx]!=xx) { xx=find(fa[xx]); return fa[xx]; } } int main() { int i,n,j,x,m; freopen("tree.in","r",stdin); scanf("%d",&n); scanf("%d",&m); for(i=1;i<=n;i++) fa[i]=i; for(i=1;i<=m;i++) scanf("%d%d%d",&edge[i].from,&edge[i].to,&edge[i].distance); sort(edge+1,edge+m+1); int fx,fy; i=1; int ans=0,cnt=0; while(cnt<n-1&&i<=m) { fx=find(edge[i].from); fy=find(edge[i].to); if(fx!=fy) { fa[fx]=fy; ans=ans+edge[i].distance; cnt++; } i++; } if(cnt<n-1) printf("orz"); else printf("%d",ans); return 0; } ```
by 生生流转 @ 2018-04-05 22:34:50


find里面 ```cpp xx=find(fa[xx]); ``` 改成 ```cpp fa[xx]=find(fa[xx]); ```
by AThousandSuns @ 2018-04-05 22:38:23


@[AThousandSuns](/space/show?uid=72118) 哦哦哦那里应该是错了 不过大佬, 改了以后还是T三个点R一个
by 生生流转 @ 2018-04-06 15:01:21


@[广秀](/space/show?uid=47458) 把freopen去掉?
by AThousandSuns @ 2018-04-06 15:21:38


@[AThousandSuns](/space/show?uid=72118) emmm我测评的时候是去掉了的 不然不会过那七个点【笑哭】 大佬费心啦
by 生生流转 @ 2018-04-06 15:56:49


好像把重载<那里 ```cpp return distance<=other.distance; ``` 改成 ```cpp return distance<other.distance; ``` 就AC了,也不知道为什么。 不过记得以后用来排序的重载运算符最好不要加=哦 (我不是大佬……hhh)
by AThousandSuns @ 2018-04-06 16:07:23


@[广秀](/space/show?uid=47458)
by AThousandSuns @ 2018-04-06 16:07:32


@[AThousandSuns](/space/show?uid=72118) 嗯咋了
by 生生流转 @ 2018-04-06 16:18:08


@[AThousandSuns](/space/show?uid=72118) 哦好的好的 多谢
by 生生流转 @ 2018-04-06 16:19:18


|