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

题目链接: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;
}
当你试图了解你的祖国时,你已踏上了犯罪的路程。
原文地址:https://www.cnblogs.com/modiz/p/3030569.html