Bzoj 1304: [CQOI2009] coloring of leaves

Source: Internet
Author: User

1#include <cstdio>2#include <iostream>3 #defineN 100094 #defineINF 1000005 using namespacestd;6 intb[n],cnt,n,m,c[n],f[n][2],head[n],next[2*n],u[2*N];7 voidJiaintA1,intA2)8 {9cnt++;Tennext[cnt]=HEAD[A1]; Onehead[a1]=CNT; Au[cnt]=A2; -     return; - } the voiddpintA1) - { -b[a1]=1; -     if(a1<=m) +       { -f[a1][c[a1]]=1; +f[a1][c[a1]^1]=inf; A         return; at       } -     Else -f[a1][0]=f[a1][1]=1; -      for(intI=head[a1];i;i=Next[i]) -       if(!B[u[i]]) -         { in DP (U[i]); -f[a1][0]+=min (f[u[i]][1],f[u[i]][0]-1); tof[a1][1]+=min (f[u[i]][1]-1, f[u[i]][0]); +         } -     return; the } * intMain () $ {Panax Notoginsengscanf"%d%d",&n,&m); -      for(intI=1; i<=m;i++) thescanf"%d",&c[i]); +      for(intI=1; i<n;i++) A       { the         inta1,a2; +scanf"%d%d",&a1,&A2); - Jia (A1,A2); $ Jia (a2,a1); $       } - DP (n); -printf"%d\n", Min (f[n][0],f[n][1])); the     return 0; -}

Tree DP Any feasible node to root the answer is the same, f[i][0] means I dianran white, 1 dyed black, so if I dianran white his child nodes dyed white nodes will not be dyed.

Bzoj 1304: [CQOI2009] coloring of leaves

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.