为啥我发出去的代码成了一坨。。
by Coding_Guy @ 2019-10-04 17:23:21
希展使M。
by A_Đark_Horcrux @ 2019-10-04 17:23:38
@[Bilion_冰凌帅](/space/show?uid=54372) 啥?
by Coding_Guy @ 2019-10-04 17:34:25
@[红鲷鱼](/space/show?uid=21272) 把你的代码前后加上```
by A_Đark_Horcrux @ 2019-10-04 17:35:24
```
#include<iostream>
#include<algorithm>
using namespace std;
int p[10001]={0};int l[10001]={0};int r[10001]={0};int dis[10001]={0};
struct edge{
int u,v,length;
bool operator > (const edge b)const
{
return this->length>b.length;
}
bool operator < (const edge b)const
{
return this->length<=b.length;
}
};
edge e[200005];int n,m;int ans=0;
int find_set(int z)
{
int tmp=z;
while(p[tmp])tmp=p[tmp];
return tmp;
}
int union_set(int x,int y)
{
if(!x||!y)return x+y;
int rch=union_set(r[x],y);
if(rch!=x)p[rch]=x;
r[x]=rch;
if(dis[l[x]]<dis[r[x]])
{
swap(l[x],r[x]);
}
dis[x]=dis[r[x]]+1;
return x;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>e[i].u>>e[i].v>>e[i].length;
}
sort(e+1,e+m+1);
for(int i=1;i<=m;i++)
{
if(find_set(e[i].u)!=find_set(e[i].v))
{
int x=find_set(e[i].u);int y=find_set(e[i].v);
union_set(x,y);ans+=e[i].length;
}
}
int root=find_set(1);int pan=1;
for(int i=2;i<=n;i++)
{
if(find_set(i)!=root)
{
pan=0;
}
}
if(pan)
{
cout<<ans;
}
else
{
cout<<"orz";
}
return 0;
}
```
by Coding_Guy @ 2019-10-04 17:37:45
哇。。谢谢大佬
by Coding_Guy @ 2019-10-04 17:38:00