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

哪位大牛帮我看看哪错了吧...WA都不行了..

Posted by 20090131 at 2009-05-12 16:05:23 on Problem 1062
#include<stdio.h>
#include<string.h>
#define INF 10000000
int m,n,cost;
int p[101],r[101],map[101][101];
void input()
{
	int i,j,k,a,b;
	scanf("%d%d",&m,&n);
	for(i=1;i<=n;i++)
		for(j=i;j<=n;j++)
			map[i][j]=map[j][i]=INF;
	for(i=1;i<=n;i++)
	{
		scanf("%d%d%d",&map[0][i],&r[i],&k);
		for(j=0;j<k;j++)
		{
			scanf("%d%d",&a,&b);
			map[a][i]=b;
		}		
	}
}

int dijkstra()
{
	   int i,j,dj[101],mark[101]={0},ii;
       cost=map[0][1];	
	   for(i = 1; i <= n; i++)
	   {
		   dj[i] = map[0][i];
       }
       for(i=r[1]-m;i<=r[1];i++)
	   {
	   int number=n;
	   memset(mark,0,sizeof(mark));
       while(number--)
	   {
		   int v,min=INF;
		   for(j=1;j<=n;j++)
			   if(mark[j]==0 && r[i]>=i && r[i]<=(i+m) && min>dj[j])
			   {
				   v=j;min=dj[j];
			   }
		   mark[v]=1;
		   for(ii = 1; ii <= n; ii++)
			   if(map[v][ii]<INF && mark[ii]==0 && r[ii]>=i && r[ii]<=(i+m) && dj[ii]>dj[v]+map[v][ii])
				   dj[ii]=dj[v]+map[v][ii];
       }
	   if(cost>dj[1]) cost=dj[1];
	   }
	   return cost;
}    
int main()
{
	input();
	printf("%d\n",dijkstra());	
	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