立聪堂德州十三局店 发表于 2022-8-11 14:08:45

POJ3107 Godfather (树的重心)

又是一道模板题......
1 #include 2 #include 3 #include 4 using namespace std; 5 const int INF=0x7f7f7f7f; 6 const int N=50005; 7 int head,to,nxt,f,size; 8 int tot,n,T,center,num; 9 10 void add(int x,int y){11   nxt[++tot]=head;12   head=tot;13   to=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;29         f=max(f,size);30   }31   f=max(f,n-size);32   if(f
页: [1]
查看完整版本: POJ3107 Godfather (树的重心)