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

找到2点半了还不知道为啥WA..网上的测试数据都能过,为什么还是WA...请教高手

Posted by fmars at 2010-08-23 02:40:32 on Problem 1062
#include<iostream>
using namespace std;
#define MAX_INT 21394453
void Dijkstra(long s,long n,long *dist) ;
long  map[1301][1301],lo[1300];
int main()
{
	long  dis[1200],m,n,cla[1200],a,b,c,i,j,k,min,up,down;
	cin>>m>>n;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			map[i][j]=MAX_INT;
	for(i=1;i<=n;i++)
	{
		cin>>map[i][n+1]>>cla[i]>>a;
		map[n+1][i]=map[i][n+1];
		for(k=1;k<=a;k++)
		{
			cin>>b>>c;
			map[i][b]=c;
			map[b][i]=c;
		}
	}
	min=MAX_INT;
	for(k=0;k<=m;k++)
	{
		up=cla[1]+k;
		down=cla[1]-m+k;
		for(i=1;i<=n+1;i++)
			lo[i]=1;
		for(i=2;i<=n;i++)
			if(cla[i]<down||cla[i]>up)
				lo[i]=0;
		Dijkstra(1,n+1,dis);
		if(dis[n+1]<min)min=dis[n+1];
	}
	cout<<min<<endl;
	return 0;
}

void Dijkstra(long s,long n,long *dist) 
{
	long vis[300];
	long i,j,min,k;
	for(i=1;i<=n;i++)
		dist[i]=map[s][i];
    for(i=1;i<=n;i++)
        vis[i]=1;
	vis[s]=0;
	for (j=1;j<n;j++){
		min = 999999999;
		for (i=1;i<=n;i++)
			if (vis[i] && dist[i]>0 && dist[i]<min &&lo[i]) {
				min = dist[i];
				k = i;
			}
		if (min == 999999999) break;
		vis[k] =0 ;
		for (i=1;i<=n;i++)
			if (vis[i] && map[k][i]!=MAX_INT &&lo[i] && (dist[k]+map[k][i]<dist[i] || dist[i] == 0)){
				dist[i] = dist[k]+map[k][i];
			}
	}	
}

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