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到死....改了12次wa了13次留念

Posted by ShenZhiBM at 2010-08-02 23:16:03 on Problem 3249 and last updated at 2010-08-02 23:19:29
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
int p[100005];
int dis[100005];
bool in[100005],out[100005];
#define inf -2002000000
struct edge
{int u,v;}arr[1005005];
int main()
{
	int i,j,u,v;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(in,0,sizeof(in));
		memset(out,0,sizeof(out));
		for(i=1;i<=n;i++)
			scanf("%d",&p[i]);
		p[0]=0;
		for(i=0;i<m;i++)
		{
			scanf("%d%d",&u,&v);
			arr[i].u=u;
			arr[i].v=v;
			in[u]=1;
			out[v]=1;
		}
		int len=m;
		for(i=1;i<=n+1;i++)
			dis[i]=inf;
		for(i=1;i<=n;i++)
		{
			if(!out[i])
			{
				arr[len].u=0;
				arr[len++].v=i;
				dis[i]=0;
			}
			if(!in[i])
			{
				arr[len].u=i;
				arr[len++].v=n+1;
			}
		}
		for(i=0;;i++)
		{
			bool bb=false;
			for(j=0;j<len;j++)
			{
				if(dis[arr[j].u]==inf)continue;
				if(dis[arr[j].v]<dis[arr[j].u]+p[arr[j].u])
				{
					dis[arr[j].v]=dis[arr[j].u]+p[arr[j].u];
					bb=true;
				}
			}
			if(!bb)break;
		}
		printf("%d\n",dis[n+1]);
	}
	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