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