您的位置:首页 > 其它

遇到的第一个上面特判题...刚开始以为样例错了...其实真错了~

2013-07-29 14:41 274 查看
题目链接:http://openoj.awaysoft.com:8080/judge/contest/contest/view.action?cid=384#problem/B





Network#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
int x,y,l;
}f[15010];
int g[1010];
int cmp(const void *a,const void *b)
{
if((* (node *)a).l==(* (node *)b).l)
{
if ((* (node *)a).y==(* (node *)b).y)
return (* (node *)a).x-(* (node *)b).x;
else
return (* (node *)a).y-(* (node *)b).y;
}
else return (* (node *)a).l-(* (node *)b).l;
}
int ff(int x)
{
if(x!=g[x]) g[x]=ff(g[x]);
return g[x];
}
int main()
{
int n,m,i,k,a,b,max=0;
int a1[150010],b1[150010];
while (~scanf("%d%d",&n,&m))
{
k=0;
for (i=0;i<m;i++)
scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].l);
for (i=1;i<=n;i++)
g[i]=i;
qsort(f,m,sizeof(f[0]),cmp);
for (i=0;i<m;i++)
{
a=ff(f[i].x);
b=ff(f[i].y);
if (a!=b)
{
if(a>b)
g[a]=b;
else
g[b]=a;
a1[k]=f[i].x;
b1[k]=f[i].y;
k++;
if(max<f[i].l)
max=f[i].l;
}
}
printf("%d\n",max);
printf("%d\n",k);
for(i=0;i<k;i++)
printf("%d %d\n",a1[i],b1[i]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐