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 201200131011 at 2013-08-02 13:40:36 on Problem 3107
#include<iostream>
#include<cstdio>
#include<vector>
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include<algorithm>
using namespace std;
vector<int>ans;
int n,minlen,minx,k;
const int  maxlen=100005;
struct Node{
	
	
	int to,next;
	
};
Node edge[maxlen];
int  box[maxlen];
int ecnt;
int  sum[maxlen];
int num[maxlen];
bool vis[maxlen];
void _make_map(int from,int to){
	edge[ecnt].to=to;
	edge[ecnt].next=box[from];
	box[from]=ecnt++;
	
}
void make_map(int from,int to){
	_make_map(from,to);
	_make_map(to,from);
	}
	
void  dfs(int u){
	num[u]=1;
    vis[u]=1;
	minx=-1;
for(int i=box[u];i;i=edge[i].next){
	int v=edge[i].to;

	 if(vis[v]) continue;
	dfs(v);
	num[u]+=num[v];
	minx=max(minx,num[v]);
}	
	sum[u]=max(minx,n-num[u]);
	
    }

int main(){
 int i, a, b;
    scanf("%d", &n);
     memset(box,0,sizeof(box));
      memset(num,0,sizeof(num));
       memset(sum,0,sizeof(sum));
        memset(vis,0,sizeof(vis));
    for(ecnt= i = 1; i < n; i ++){
        scanf("%d%d", &a, &b);
       make_map(a,b);
    }
    
  minlen=1000000000;
    dfs(1);	
    
	for(int i=1;i<=n;i++){
	 	
	 
 	if(sum[i]<minlen){
		ans.clear();
		minlen=sum[i];
		ans.push_back(i);
	}
	else if(sum[i]==minlen){
		ans.push_back(i);
	}
 	
 }
		sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++)
		{  printf("%d",ans[i]);
			printf(" ");
		
			}	
}

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