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

我的程序为什么TLE了? 高手解释一下:

Posted by zhb_msqx at 2007-08-17 18:35:48 on Problem 2395
#include <iostream>
#include <fstream>
using namespace std;

#define Max 10000

int n,m;
int edge[Max][Max];//表明一条无向边
int mark[2000]; //标记第i个农场是否在最小生成树里面


int marknum;


void prim(){
	mark[1]=1;
	marknum++;
	int maxmin=0;
	while(marknum!=n){
		int mincost=11000;
		int nodei=0;int nodej=0;
		for(int i=1;i<=n;i++){
			if(mark[i]==1){ //表明这个点已经在最小生成树里面了				
				for(int j=1;j<=n;j++){
					if(mark[j]==0&&edge[i][j]<mincost){
						mincost=edge[i][j];
						nodei=i;
						nodej=j;		
					}
				}
			}
		}
		if(mincost>maxmin)maxmin=mincost;

		mark[nodej]=1;
		marknum++;

	}
	cout<<maxmin<<endl;
}


void init(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			edge[i][j]=Max;
		}
	}
	marknum=0;
	memset(mark,0,sizeof(mark));
}

void main(){
//	ifstream in("data.txt");
	cin>>n>>m;
	init();
	for(int tmp=0;tmp<m;tmp++){
		int x,y,cost;
		cin>>x>>y>>cost;
	//	cout<<x<<" "<<y<<" "<<cost<<endl;
		edge[x][y]=cost;edge[y][x]=cost;
	}
	prim();
}

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