[2017] six provinces exam destroy "tree view"

Description

  https://loj.ac/problem/2144

Solution

  DP bare tree problem is to spell out the two paths a little trouble.
  Reference in this blog practices.
  Set \ (dp (i, 0) \) represented by \ (I \) subtree rooted at point number, a single-stranded through the root, the number of split blocks communication. Note that only consider \ (i \) subtree rooted, not \ (i \) outside that a Dalian-block where his father! The following (3 \) \ states Similarly
  \ (dp (i, 1) \) represented by \ (I \) subtree rooted at point number, but there is a path to the root, the number of split blocks communication.
  \ (dp (i, 2) \) represented by \ (I \) subtree rooted dot, there is a path through the root, the number of split blocks communication.
  \ (dp (i, 3) \) represented by \ (I \) sub-tree rooted dot, there is a path (whether through the roots, however), and a root through the single-chain, the number of split blocks communication.
  Then the answer is clearly above can be used \ (4 \) states spell it out.
  Shot against violence against each shoot one kind of did not take into account the transfer to add, and then finished it ......
  complexity \ (O (the n-) \) .

  code

Guess you like

Origin www.cnblogs.com/scx2015noip-as-php/p/loj2144.html