@[lutaiye](/space/show?uid=48311)
@[钟梓俊](/space/show?uid=48269)
@[Leo_JAM](/space/show?uid=28147)
@[刘翔乐](/space/show?uid=49446)
by Corrine @ 2018-04-01 10:53:27
@[刘翔乐](/space/show?uid=49446)
by Corrine @ 2018-04-01 10:59:39
@zengjunkai 找到错了,程序如下,您的len处理的不好:
```
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k,ans=0;
struct nodb{int x,y,s1,s2,gg,v,i;}e[20005],b[20005];
struct nod{int x,y;}s[20005];
int la[20005],f[20005];
bool cmp1(nodb x,nodb y){return x.s1<y.s1;}
bool cmp2(nodb x,nodb y){return x.s2<y.s2;}
bool cmp3(nod x,nod y){return x.x<y.x;}
int ch(int x){if(x==f[x])return x;return f[x]=ch(f[x]);}
int main()
{
scanf("%d %d %d",&n,&k,&m);
for(int i=1;i<m;i++)
{
scanf("%d %d %d %d",&e[i].x,&e[i].y,&e[i].s1,&e[i].s2);
e[i].v=1;
e[i].i=i;
}
int len=0;
for(int i=1;i<=n;i++){la[i]=0;f[i]=i;}
int kk=0;
sort(e+1,e+1+m,cmp1);
for(int i=1;i<=m;i++)
{
if(e[i].v==1)
{
int xx=ch(e[i].x);
int yy=ch(e[i].y);
if(xx!=yy)
{
f[xx]=yy;
e[i].v=0;
s[++len].x=e[i].i;
s[len].y=1;
if(ans<e[i].s1)
{
ans=e[i].s1;
}
kk++; if(kk==k) break;
}
}
}
kk=0;
sort(e+1,e+1+m,cmp2);
for(int i=1;i<=m;i++)
{
if(e[i].v==1)
{
int xx=ch(e[i].x);
int yy=ch(e[i].y);
if(xx!=yy)
{
f[xx]=yy;
e[i].v=0;
s[++len].x=e[i].i;
s[len].y=2;
if(ans<e[i].s2)
{
ans=e[i].s2;
}
kk++; if(kk==n-1-k) break;
}
}
}
printf("%d\n",ans);
sort(s,s+1+len,cmp3);
for(int i=1;i<=len;i++)
{
printf("%d %d\n",s[i].x,s[i].y);
}
return 0;
}
```
by Drinkkk @ 2018-04-01 11:00:40
@[TIMI_k](/space/show?uid=49368)
by Drinkkk @ 2018-04-01 11:00:53
@[钟梓俊](/space/show?uid=48269) 哦,知道啦
by Corrine @ 2018-04-01 11:04:10