| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
又是神奇的G++ 就AC。 C++ 就 WA…… 样例不算错,只要能输出最小。毕竟 Special Judge !!!!!!!!
求大神路过 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator