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