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

O(n^3)过不了

Posted by ecjtubaowp at 2007-09-05 10:41:16 on Problem 3268
In Reply To:floyd不是非常方便么?但是TLE? 高手能告诉我为什么么??谢谢!! Posted by:kikif at 2007-09-05 10:15:48
> #include <iostream>
> #include <fstream>
> #include <stdio.h>
> using namespace std;
> #define INF 100000
> 
> int a[1010][1010];
> int n,m,x;
> 
> void main(){
> //	ifstream cin("data.txt");
> //	cin>>n>>m>>x;
> 	scanf("%d%d%d",&n,&m,&x);
> 	int i,j,k;
> 	for(i=1;i<=n;i++){
> 		for(j=1;j<=n;j++){
> 			if(i==j)a[i][j]=0;
> 			else{
> 				a[i][j]=INF;
> 			}
> 		}
> 	}
> 	for(i=0;i<m;i++){
> 		int f,t,cost;
> 		//cin>>f>>t>>cost;
> 		scanf("%d%d%d",&f,&t,&cost);
> 		a[f][t]=cost;
> 	}
> 	for(k=1;k<=n;k++){   //floyd
> 		for(i=1;i<=n;i++){
> 			for(j=1;j<=n;j++){
> 				if(a[i][k]+a[k][j]<a[i][j])a[i][j]=a[i][k]+a[k][j];
> 			}
> 		}
> 	}
> 	int max=-1;
> 	for(i=1;i<=n;i++){
> 		int tmp=a[i][x]+a[x][i];
> 		if(tmp>max)max=tmp;
> 	}
> 	cout<<max<<endl;
> 
> }

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