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