POJ3107-Godfather tree DP... use vector with caution...

Source: Internet
Author: User
Submission timeout .. I really think there is nothing to optimize... it can be changed back to the bottom of the BFS .. but it's troublesome. remember a bunch of things .. look at discuss to know the main reason for the vector .. into a handwritten linked list .. after Ms, select any vertex as the root of the tree... count the number of subtree elements of each vertex... "/> <scripttype =" text/javascript "submission timeout .. I really think there is nothing to optimize... it can be changed back to the bottom of the BFS .. but it's troublesome. remember a bunch of things .. look at discuss to know the main reason for the vector .. into a handwritten linked list .. after Ms, select any vertex as the root of the tree... count the number of subtree elements of each vertex .. for vertices that are not root .. subtract the number of all points N from the number of elements in the current subtree num. as another child of the point... program:
#include
 
  #include
  
   #include
   
    #include
    
     #include
     
      #include#include
      
       #include
       
        #include
        #define oo 1000000007#define ll long long#define pi acos(-1.0)#define MAXN 50005using namespace std; struct node{ int x,y,next;}line[MAXN*2]; int n,AnsNum,AnsData,ans[MAXN],_next[MAXN];bool used[MAXN];void addline(int x,int y,int m){ line[m].next=_next[x],_next[x]=m; line[m].x=x,line[m].y=y; return;}int dfs(int x){ int MaxSub=0,num=0,t,k; k=_next[x]; while (k) { if (!used[line[k].y]) { used[line[k].y]=true; t=dfs(line[k].y); MaxSub=max(t,MaxSub); num+=t; used[line[k].y]=false; } k=line[k].next; } MaxSub=max(MaxSub,n-(num+1)); if (MaxSub==AnsData) ans[++AnsNum]=x; else if (MaxSub

 


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.