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

最长路是NP的。。。

Posted by e_at_fdu at 2005-10-19 17:20:31 on Problem 1201
In Reply To:求负权的单源最短路是不是等于求正权的单源最长路?我的代码WA了-_-|| Posted by:animate at 2005-10-19 15:19:12
> #include<cstdio>
> #include<iostream>
> using namespace std;
> 
> int n,m,s;
> int E[100200][3];
> int D[50100];
> 
> void BellmanFord(){
> 	int i,j,k;
> 	for(i=s;i<=m;i++)D[i]=1;
> 	D[s]=0;
> 	for(k=1;k<=m;k++){
> 		
> 		for(j=0;j<n;j++){
> 			int u=E[j][0],v=E[j][1],e=E[j][2];
> 			if(D[u]!=1&&D[v]>D[u]+e){
> 				D[v]=D[u]+e;
> 			}
> 		}
> 		
> 	}
> 	
> 	printf("%d\n",-D[m]);
> }
> 
> int main(){
> 	//freopen("in.txt","r",stdin);
> 	scanf("%d",&n);
> 	int i;
> 	int u,v,e;
> 	m=-1;s=-1;
> 	
> 	for(i=0;i<n;i++){
> 		scanf("%d%d%d",&u,&v,&e);
> 		E[i][0]=u;
> 		if(s==-1||s>u)s=u;
> 		E[i][1]=v+1;
> 		if(v+1>m)m=v+1;
> 		E[i][2]=-e;
> 	}
> 	
> 	for(i=s;i<m;i++){
> 		E[n][0]=i;
> 		E[n][1]=i+1;
> 		E[n][2]=0;
> 		n++;
> 	}
> 	
> 	BellmanFord();
> 	
> }

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