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

为什么加上这句程序会崩呢???不然就a了

Posted by zhangweinan at 2011-07-24 19:47:22 on Problem 3268
#include<iostream>
using namespace std;
#define MAX 1001
#define INF 2000000
int map[MAX][MAX];
int visit[MAX];
int n,m,x;

void di(int s,int dis[])
{
	int i,j;
	memset(visit,0,sizeof(visit));
	for(i=1;i<=n;i++)
	{
		if(i!=s)
		dis[i]=map[s][i];
	}
	dis[s]=0;
      //visit[s]=1;  
	for(i=1;i<=n;i++)
	{
		int min=INF;
		int ff;
		for(j=1;j<=n;j++)
		{
			if(!visit[j]  &&  dis[j]<min)
			{
				min=dis[j];
				ff=j;
			}
		}
		visit[ff]=1;
		for(j=1;j<=n;j++)
		{
			if(!visit[j]  &&  dis[ff]+map[ff][j]<dis[j])
				dis[j]=dis[ff]+map[ff][j];
		}
	}
}
void tra()
{
	int i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<i;j++)
		{
			int t;
			t=map[i][j];
			map[i][j]=map[j][i];
			map[j][i]=t;
		}
}


int main()
{
	int i,j;
	int dis1[MAX];
	int dis2[MAX];
	cin>>n>>m>>x;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			map[i][j]=INF;
	int s,d,c;
	for(i=1;i<=m;i++)
	{
		cin>>s>>d>>c;
		map[s][d]=c;
	}
	di(x,dis1);
	tra();
	di(x,dis2);
	int max=0;
	for(i=1;i<=n;i++)
	{
		if(dis1[i]+dis2[i]<INF  && dis1[i]+dis2[i]>max )
			max=dis1[i]+dis2[i];
	}
	cout<<max<<endl;
	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