POJ3107-Godfather tree DP... vector with caution... _ PHP Tutorial

Source: Internet
Author: User
POJ3107-Godfather tree DP... vector with caution .... 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 .. 500 M 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 .. over 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
        # Define oo 1000000007 # define ll long # define pi acos (-1.0) # define MAXN 50005 using 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.