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 zhb_msqx at 2007-08-25 20:10:46 on Problem 2378
#include <iostream>
#include <fstream>
using namespace std;
#define Max 1000

int g[Max][Max]; //邻接表
int dest[Max];  //记录去除这一点以后它的最大权值

int mark[Max];
int n;

int dfs(int p,int exp){
	mark[p]=1;
	int depth=1;
	for(int i=1;i<=n;i++){
		if(g[p][i]==1&&mark[i]==0&&i!=exp&&i!=p){
			mark[i]=1;
			depth+=dfs(i,exp);
		}
	}
	return depth;
}
void main(){
//	ifstream cin("data.txt");
	cin>>n;
	memset(dest,0,sizeof(dest));
	memset(g,0,sizeof(g));
	memset(mark,0,sizeof(mark));

	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		g[x][y]=g[y][x]=1;
	}

	for(i=1;i<=n;i++){ //去除这一点
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				mark[k]=0;
			}
			mark[i]=1;
			if(j!=i&&g[i][j]==1){
				int tmp=dfs(j,i);
				if(tmp>dest[i])dest[i]=tmp;
			}
		}
	//	cout<<dest[i]<<endl;
	}
	for(i=1;i<=n;i++){
		if(dest[i]<=n/2)cout<<i<<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