Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

又是神奇的G++ 就AC。 C++ 就 WA…… 样例不算错,只要能输出最小。毕竟 Special Judge !!!!!!!!

Posted by dongshimou at 2014-07-04 20:20:04 on Problem 1861
求大神路过 Debug。

C++  WA了。
G++  AC了。


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
using namespace std;
int n,m;
struct lx
{
    int u,v,len;
    bool vis;
} l[500*1001];
int fa[1001];
bool cmp(lx a,lx b)
{
    return a.len<b.len;
}
int father(int x)
{
    if(x!=fa[x])
        return fa[x]=father(fa[x]);
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=0;i<m;i++)
            scanf("%d%d%d",&l[i].u,&l[i].v,&l[i].len),l[i].vis=0;
        for(int i=0;i<=n;i++)
            fa[i]=i;
        sort(l,l+m,cmp);
        int len=0,maxe=0;
        for(int i=0;i<m;i++)
        {
            int fu=father(l[i].u);
            int fv=father(l[i].v);
            if(fu==fv)continue;
            fa[fv]=fu;
            l[i].vis=1;
            maxe++;
            len=max(len,l[i].len);
        }
        printf("%d\n%d\n",len,maxe);
        for(int i=0;i<m;i++)
        {
            if(l[i].vis==1)
                printf("%d %d\n",l[i].u,l[i].v);
        }
    }
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator