马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
又是一道模板题......
[code] 1 #include 2 #include 3 #include 4 using namespace std; 5 const int INF=0x7f7f7f7f; 6 const int N=50005; 7 int head[N],to[N*2],nxt[N*2],f[N],size[N]; 8 int tot,n,T,center,num; 9 10 void add(int x,int y){11 nxt[++tot]=head[x];12 head[x]=tot;13 to[tot]=y;14 }15 16 void init(){17 memset(head,0,sizeof(head));18 tot=0;19 center=num=0;20 }21 22 void dfs(int u,int fa){23 size=1,f=0;24 for(int i=head;i;i=nxt){25 int v=to;26 if(v==fa) continue;27 dfs(v,u);28 size+=size[v];29 f=max(f,size[v]);30 }31 f=max(f,n-size);32 if(f |