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

数据太弱了。这样的程序也能A(有数据为证,明显not unique)

Posted by peter1341 at 2014-09-17 14:57:41 on Problem 1679
/*********数据*****/
1
4 4
1 2 3
2 3 1
3 4 3
4 1 1
/*********数据*****/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
#define N 105
#define INF 99999999
int map[N][N];
int dis[N];
int visit[N];
int n;
void prim()
{
	int i,j,v,min,k,flag,sum;
	for(i=1;i<=n;i++)
	dis[i]=map[1][i];
	flag=0;
	sum=0;
	memset(visit,0,sizeof(visit));
	for(i=1;i<=n;i++)
	{
		min=INF;
		for(j=1;j<=n;j++)
		if(!visit[j]&&dis[j]<min)
		{
			min=dis[j];
			v=j;
		}
		k=0;
	    for(j=1;j<=n;j++)
		if(visit[j]&&map[v][j]==min)
		k++;
		if(k>1)
		{
			flag=1;
			break;
		}
		visit[v]=1;
		sum+=min;
		for(j=1;j<=n;j++)
		if(!visit[j]&&dis[j]>map[v][j])
		dis[j]=map[v][j];
	}
	if(flag)
	printf("Not Unique!\n");
	else
	printf("%d\n",sum);
}
int main()
{
	int t;
	int i,j,m;
	int a,b,c;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			map[i][j]=INF;
			if(i==j)
			map[i][j]=0;
		}
		while(m--)
		{
			scanf("%d%d%d",&a,&b,&c);
			if(map[a][b]>c)
			{
				map[a][b]=map[b][a]=c;
			}
		}
		prim();
	}
	return 0;
}

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