POJ3107 Godfather (树的重心)

打印 上一主题 下一主题

主题 1030|帖子 1030|积分 3090

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

立聪堂德州十三局店

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表