BZOJ1369 [Baltic2003]gem

Source: Internet
Author: User

is a simple tree DP ~ But the question is, how many colors do you want?

I began to write 25 in the color of the hand, and found that very slow ah ... So I did a dead change to three kinds of handed up to unexpectedly past ... After the ... (To know 2 colors must be wrong ah ...) )

1 /**************************************************************2 problem:13693 User:rausen4 language:c++5 result:accepted6 Time:12 Ms7 memory:1820 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <algorithm> A   - using namespacestd; - Const intN = 1e4 +5; the Const intINF =1e9; - Const intC =3; -   - structEdge { +     intnext, to; - Edge () {} +Edgeint_n,int_t): Next (_n), to (_t) {} A} e[n <<1]; at   - intN, ans; - intfirst[n], tot; - intf[n][ +]; -   -InlineintRead () { in     intx =0; -     CharCH =GetChar (); to      while(Ch <'0'||'9'<ch) +CH =GetChar (); -      while('0'<= CH && Ch <='9') { thex = x *Ten+ CH-'0'; *CH =GetChar (); $     }Panax Notoginseng     returnx; - } the   +   AInlinevoidAdd_edges (intXinty) { theE[++tot] = Edge (first[x], y), first[x] =tot; +E[++tot] = Edge (First[y], x), first[y] =tot; - } $   $ #defineY e[x].to - voidWorkintPintFA) { -     intx, I, J, MN; the      for(i =1; I <= C; ++i) F[p][i] =i; -      for(x = first[p]; x; x =e[x].next)Wuyi         if(Y! =fa) Work (Y, p); the      for(i =1; I <= C; ++i) { -          for(x = first[p]; x; x =e[x].next) Wu             if(Y! =FA) { -                  for(j =1, MN = inf; J <= C; ++j) About                     if(I! = j) mn =min (mn, f[y][j]); $F[p][i] + =mn; -             } -     } - } A #undefY +   the intMain () { -     inti; $n =read (); the      for(i =1; I < n; ++i) the add_edges (read (), read ()); theWork1,0); the      for(i =1, ans = inf; I <= C; ++i) -ans = min (ans, f[1][i]); inprintf"%d\n", ans); the     return 0; the}
View Code

BZOJ1369 [Baltic2003]gem

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.