"Spoj" "1825" free Tour 2

Source: Internet
Author: User

Point Division Treatment

Example of Point Division 2 (the subject code results in tle ... )

Strongly condemn card time limit qaq,t countless times ah numerous ...

But in the static error of n times, it deepened the understanding of the Point Division rule ... It's a blessing. (Self-consolation)

1 //SPOJ 18252#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <iostream>6#include <algorithm>7 #defineRep (i,n) for (int i=0;i<n;++i)8 #defineF (i,j,n) for (int i=j;i<=n;++i)9 #defineD (i,j,n) for (int i=j;i>=n;--i)Ten using namespacestd; OneInlinevoidReadint&v) { Av=0;intsign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} thev*=Sign ; - } - /******************tamplate*********************/ - Const intn=200010, inf=1e8; + intn,m,k,root=0, h[n],s[n],g[n],f[n],size,d[n]; - BOOLVis[n],black[n]; + intto[n],head[n],next[n],len[n],tot=0; AInlinevoidInsintXintYintl) { atTo[++tot]=y; NEXT[TOT]=HEAD[X]; Head[x]=tot; len[tot]=l; -To[++tot]=x; Next[tot]=head[y]; Head[y]=tot; len[tot]=l; - } -  -InlinevoidGetroot (intXintFA) { -s[x]=1; h[x]=0; in      for(intI=head[x];i;i=Next[i]) -         if(TO[I]!=FA &&!)Vis[to[i]]) { to Getroot (to[i],x); +s[x]+=S[to[i]]; -             //H[x]=max (H[x],s[to[i]); the             if(S[to[i]]>h[x]) h[x]=S[to[i]]; *         } $H[x]=max (h[x],size-s[x]);Panax Notoginseng     if(H[x]x; - } the  +InlinevoidGETDEP (intXintFA) { A     intres=0; the      for(intI=head[x];i;i=Next[i]) { +         if(TO[I]!=FA &&!)Vis[to[i]]) { -d[to[i]]=d[x]+Black[to[i]]; $ GETDEP (to[i],x); $res=Max (Res,d[to[i]]); -         } -     } thed[x]+=Res; - }WuyiInlinevoidGETG (intXintFaintLengintc) { theg[c]=Max (G[c],leng); -      for(intI=head[x];i;i=Next[i]) Wu         if(To[i]!=fa &&!vis[to[i]) GETG (to[i],x,leng+len[i],c+Black[to[i]]); - } About structnode{intDeep,to,len;} St[n]; $InlineBOOLcmpConstNode &a,ConstNode &b) {returna.deep<B.deep;} - intans=0, CNT; -  - voidGetans (intx) { Avis[x]=1; +      for(intI=head[x];i;i=Next[i]) the GETDEP (to[i],x); -Cnt=0; $F (I,0, N) f[i]=0; the      for(intI=head[x];i;i=Next[i]) { the         if(!Vis[to[i]]) { thed[to[i]]=Black[to[i]]; the GETDEP (to[i],x); -st[cnt++]=(node) {d[to[i]],to[i],len[i]}; in         } the     } theSort (st,st+cnt,cmp); About Rep (i,cnt) { the         inty=st[i].to; theF (J,0, D[y]) g[j]=-INF; the GETG (Y,x,st[i].len,black[y]); +         if(i>0){ -             intEnd=min (K-black[x],d[y]); theF (J,0, end) {Bayi                 intP=min (d[st[i-1].to],k-j-black[x]); the                 if(F[p]==-inf) Break; the                 if(G[j]!=-inf) Ans=max (ans,g[j]+f[p]); -             } -         } theF (J,0, D[y]) { thef[j]=Max (f[j],g[j]); the             if(j) F[j]=max (f[j],f[j-1]); the             if(j+black[x]<=k) ans=Max (ans,f[j]); -         } the     } the      the      for(intI=head[x];i;i=Next[i])94         if(!Vis[to[i]]) { theroot=0; Size=S[to[i]]; the Getroot (to[i],x); the Getans (root);98         } About } - 101 intMain () {102 //freopen ("1825.in", "R", stdin);103 Read ( n); Read (k); Read (m);104     intx,y,l; theF (I,1, m) {read (x); black[x]|=1;}106F (I,2, N) {107 Read (x); Read ( y); read (l);108 ins (x,y,l);109     } theroot=0; Size=n; h[root]=INF;111Getroot (1,0); the Getans (root);113printf"%d\n", ans); the     return 0; the}
View Code

"Spoj" "1825" free Tour 2

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.