和TLE有仇!!kruskal为什么TLE??

P3366 【模板】最小生成树

@[DOs__lx](/user/261006) find建议这么写 ```cpp return fa[x]==x?x:fa[x]=find(fa[x]); ```
by Smile_Cindy @ 2020-02-16 12:24:06


把find里的while换成if试试?
by Xhesika_Frost @ 2020-02-16 12:24:50


@[DOs__lx](/user/261006) 您的双向边呢
by 良知 @ 2020-02-16 12:25:55


kruskal要啥双向边。。。。
by jerry3128 @ 2020-02-16 12:34:51


@[DOs__lx](/user/261006) 因为你写错了
by cnyzz @ 2020-02-16 12:35:30


@[DOs__lx](/user/261006) 建议在学学并查集……
by __gcd @ 2020-02-16 12:35:50


``` inl int find(int x){ if(x == fa[x]) { return x; } return fa[x] = find(fa[x]); } ```
by __gcd @ 2020-02-16 12:36:52


并查集都是楼上那么写的吧 ~~~ int find(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]) ; }
by 1saunoya @ 2020-02-16 12:37:51


启发式合并: ```cpp void unionn(int x,int y){ int fx=find(x),fy=find(y); if(fx==fy) return; if(size[fx]<=size[fy]){ size[fy]+=size[fx]; father[fx]=fy; } else{ size[fx]+=fy; father[fy]=fx; } return; } ```
by raincity @ 2020-02-16 12:48:53


蟹蟹各位大佬,现在A了
by DOs__lx @ 2020-02-16 12:50:20


| 下一页