POJ 3107-godfather-Tree DP. Vector with caution ... _php tutorial

Source: Internet
Author: User
Tags cmath
Commit Time-out: I really feel that there is nothing better to optimize ... Back up to the bottom of the BFS. But good trouble, remember a bunch of things. See discuss only to know the main reason is vector. Change to a handwritten list. 500MS over,,, Select any of the points to do tree root ... Count the number of sub-tree elements for each point: For points that are not root: Subtracts all points n minus the number of elements in the current subtree Num. As the point of another child ... 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


http://www.bkjia.com/PHPjc/477206.html www.bkjia.com true http://www.bkjia.com/PHPjc/477206.html techarticle commit Time-out: I really feel that there is nothing better to optimize ... Back up to the bottom of the BFS. But good trouble, remember a bunch of things. See discuss only to know the main reason is vector. Change to a handwritten list. 500M ...

  • 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.