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

差分约束也超时啊。。。请大家指导。。。谢谢

Posted by bigheadghost at 2006-11-15 19:54:07 on Problem 1201
#include<cstdio>
#define INF 200000000
struct EDGE
{
	int st,ed,val;
}edge[1000000];
int dist[50002];
int n,result,max,min,nv;
bool inG[50002];
int getmin(int a,int b)
{
	if(a<b)
		return a;
	else
		return b;
}
int getmax(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
void BellmanFord()
{
	int v,e,s=min;	
	for(v=min;v<max;v++)
	{
		dist[v]=-INF;
		edge[n].st=v;
		edge[n].ed=v+1;
		edge[n].val=0;
		n++;
		edge[n].st=v+1;
		edge[n].ed=v;
		edge[n].val=-1;
		n++;
	}	
	dist[s]=0;
	bool over=false;
	for(v=0;v<max-min&&!over;v++)
	{
		over=true;
		for(e=0;e<n;e++)
			if(dist[edge[e].st]!=-INF&&dist[edge[e].ed]<dist[edge[e].st]+edge[e].val)
			{
				dist[edge[e].ed]=dist[edge[e].st]+edge[e].val;
				over=false;
			}
	}	
	result=dist[max];
}	
int main()
{
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&edge[i].st,&edge[i].ed,&edge[i].val);
		edge[i].ed++;
		max=getmax(max,edge[i].ed);
		min=getmin(min,edge[i].st);
	}	
	BellmanFord();
	printf("%d\n",result);
	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