Test instructions
A tree that has n nodes, deletes a point, gets the largest branch of the Unicom minimum, and asks for such a set of points
Analysis:
Dp[i] means to delete the largest Unicom branch I obtained, traversing the node, the problem with the vector will time out
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineN 50010#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;intDp[n],n,num[n],used[n],ans[n],len,head[n];structedge{intT,next;} E[n*2];intMaxintAintb) { returnA>b?a:b;}voidAddintAintb) {e[len].t=b; E[len].next=Head[a]; Head[a]=len++;}intDfsintroot) {Num[root]=1; Used[root]=1; for(inti=head[root];i!=-1; i=E[i].next) { intson=e[i].t; if(Used[son])Continue; Num[root]+=Dfs (son); Dp[root]=Max (Dp[root],num[son]); } Dp[root]=max (dp[root],n-Num[root]); returnnum[root];}intMain () { while(~SCANF ("%d",&N)) {memset (DP,0,sizeof(DP)); memset (Used,0,sizeof(used)); memset (Head,-1,sizeof(head)); intb; Len=0; for(intI=0; i<n-1;++i) {scanf ("%d%d",&a,&b); Add (A, b); Add (B,a); } DFS (1); intl,minv=INF; for(intI=1; i<=n;++i) { if(dp[i]<MINV) {L=0; Ans[l++]=i; MINV=Dp[i]; } Else if(dp[i]==MINV) Ans[l++]=i; } for(intI=0; i<l;++i) {printf ("%d", Ans[i]); } printf ("\ n"); }return 0;}
POJ 3107-godfather (tree-shaped DP)