Codeforces 1247 F. Tree Factory

Revision en1, by vrqq, 2019-10-27 16:28:52

Hit point: To prove these ideas:

  • for some node P, all node in the subtree of Node p are appearing consecutive in bamboo tree.
  • We named the consecutive nodes built up a section in bamboo tree.
  • If node-A have three child: P, Q, R. The section of P, Q, R will range one by one in bamboo tree: A,[P],[Q],[R] or A[Q][R][P] or ...
  • We assume 2 scenario:
    • The right answer of bamboo is A,[P],[Q],[R]. The number of steps we move [Q] to A + defragment [P]
    • The right answer of bamboo is A,[Q],[P],[R]. The number of steps we move [Q] to A + defragment [P]
    • Are equal.

An easy reading graphic and code are on my blog : (With Chinese explanation)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English vrqq 2019-10-27 16:29:52 3 Tiny change: 'my blog : ![https://b' -> 'my blog : \n[https://b'
en1 English vrqq 2019-10-27 16:28:52 779 Initial revision (published)