"Distance gdkoi:44 days &gdoi:107 days" "BZOJ1040" [ZJOI2008] Knight

Source: Internet
Author: User

In fact, is ready to retire, but Gdoi will continue to learn before!! As an interest in learning, has lost confidence in the competition, I still go back to kneel down the Culture class bar Qaq

First ring set of tree DP ... In fact, the idea is very simple, the ring apart, classified processing. If the two points opened are u,v,dp[i,0..1] respectively, the knight is not selected and selected

(1) Do not choose U,v Point Random (2) u random, V-point not selected ...

Classified DP processing can be

1 Constmaxn=1000419;2 type3Edgetype=Record4 Toward,next:longint;5  End;6 7 var8EdgeArray[0.. maxn*2] ofEdgetype;9FirstArray[0.. MAXN] ofLongint;TenValArray[0.. MAXN] ofInt64; OneDp:Array[0.. MAXN,0..1] ofInt64; APD,VB,VC:Array[0.. MAXN] ofBoolean; - Root,vv,e,tot:longint; - N:longint; the functionMax (X,y:int64): Int64;begin ifX>y ThenExit (x)ElseExit (y);End; -  - procedureAddedge (i,j:longint); - begin +edge[tot].toward:=J; -edge[tot].next:=First[i]; +first[i]:=tot; A Inc (TOT); at End; -  - procedureAdd (i,j:longint); - begin - Addedge (I,J); Addedge (j,i); - End; in  - procedureDFS (v,fa:longint); to varI,tmp:longint; + begin -pd[v]:=true; thei:=First[v]; *   whilei<>-1  Do $   beginPanax Notoginsengtmp:=Edge[i].toward; -    if  notPD[TMP] Thendfs (TMP,V) the     Else ifTmp<>fa Then +      begin Avv:=v; theroot:=tmp; +e:=i; -      End; $i:=Edge[i].next; $   End; - End; -  the procedureDPB (V:longint); //ban U - varI,tmp:longint;Wuyi begin theDp[v,0]:=0; Dp[v,1]:=VAL[V]; vb[v]:=true; -i:=First[v]; Wu   whilei<>-1  Do -   begin Abouttmp:=Edge[i].toward; $    if(i<>e) and(I XOR1&LT;&GT;E) and  notVB[TMP] Then -     begin - DPB (TMP); -Dp[v,0]:=dp[v,0]+max (Dp[tmp,0],dp[tmp,1]); ADp[v,1]:=dp[v,1]+dp[tmp,0]; +     End; thei:=Edge[i].next; -   End; $ End; the  the procedureDPC (V:longint); //ban V; the varI,tmp:longint; the begin -Dp[v,0]:=0; Dp[v,1]:=VAL[V]; vc[v]:=true; ini:=First[v]; the   whilei<>-1  Do the   begin Abouttmp:=Edge[i].toward; the    if(i<>e) and(I XOR1&LT;&GT;E) and  notVC[TMP] Then the     begin the DPC (TMP); +Dp[v,1]:=dp[v,1]+dp[tmp,0]; -      ifTmp=vv ThenDp[v,0]:=dp[v,0]+dp[tmp,0] the       ElseDp[v,0]:=dp[v,0]+max (Dp[tmp,0],dp[tmp,1]);Bayi     End; thei:=Edge[i].next; the   End; - End; -  the proceduresolve; the varI:longint; the Rec,ans:int64; the begin -ans:=0; the   fori:=1  toN Do the   if  notPd[i] Then the    begin94rec:=0; root:=-1; DFS (i,-1); theDPB (root); Rec:=dp[root,0]; theDPC (root); Rec:=max (Rec,max (Dp[root,0],dp[root,1])); the Inc (ANS,REC);98    End; About writeln (ans); - End;101 102 procedureInit;103 varI,x:longint;104 begin theFillchar (first,sizeof (first),255);106 READLN (n);107tot:=0;108   fori:=1  toN Do109   begin the readln (val[i],x);111 Add (i,x); the   End;113 End; the  the Begin the Init;117 solve;118End.

"Distance gdkoi:44 days &gdoi:107 days" "BZOJ1040" [ZJOI2008] Knight

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.