HDU 5016 Mart Master II (tree verbose)

Source: Internet
Author: User

HDU 5016 Mart Master II (tree verbose)


First, the DFS pre-processes the distance between each point and the number of the base station.
Find the center of gravity, find the distance from each point to the center of gravity, and then, according to dis [x] + dis [y] <d [y], use two points to find the number that is not occupied in the current subtree. The total number of points minus the number that is occupied. In this way, we can find the maximum number of vertices occupied by each vertex. Find the maximum value.
The Code is as follows:

#include 
  
   #include 
   
    #include 
    
     #include 
     
      #include #include 
      
       #include
       #include 
        
         #include 
         
          #include 
          
           using namespace std;#define LL __int64#define pi acos(-1.0)#pragma comment(linker, /STACK:1024000000)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=100000+10;int head[MAXN], cnt, root, min1, tot;int siz[MAXN], vis[MAXN], d[MAXN], id[MAXN], ans[MAXN], dis[MAXN];int color[MAXN];struct node{ int v, w, next;}edge[MAXN<<1];void add(int u, int v, int w){ edge[cnt].v=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++;}struct N{ int dis, id;}F[MAXN];bool cmp(N x, N y){ return x.dis
           
            d[v]+edge[i].w){ d[u]=d[v]+edge[i].w; id[u]=id[v]; } else if(d[u]==d[v]+edge[i].w) id[u]=min(id[u],id[v]); }}void dfs2(int u, int fa){ for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(v==fa) continue ; if(d[v]>d[u]+edge[i].w){ d[v]=d[u]+edge[i].w; id[v]=id[u]; } else if(d[v]==d[u]+edge[i].w){ id[v]=min(id[v],id[u]); } dfs2(v,u); }}void getsize(int u, int fa){ siz[u]=1; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(v==fa||vis[v]) continue ; getsize(v,u); siz[u]+=siz[v]; }}void getroot(int u, int fa, int s){ int max1=0; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(v==fa||vis[v]) continue ; getroot(v,u,s); max1=max(max1,siz[v]); } max1=max(max1,s-siz[u]); if(min1>max1){ min1=max1; root=u; }}void getdis(int u, int fa, int l){ dis[u]=l; F[tot].dis=d[u]-l; F[tot++].id=id[u]; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(v==fa||vis[v]) continue ; getdis(v,u,l+edge[i].w); }}int BS(int l, int u){ int low=0, high=tot-1, mid, ans=-1; while(low<=high){ mid=low+high>>1; if(F[mid].dis
            
           
          
         
        
      
     
    
   
  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.