Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

CppC_solver's blog

By CppC_solver, history, 2 months ago, In English

Do you personally prefer tree problem with $$$N-1$$$ pair of integers input where $$$i^{th}$$$ input ($$$u_i$$$ and $$$v_i$$$) denotes the nodes that $$$i^{th}$$$ edge connects and all the edges guarantee a tree, or $$$N-1$$$ integers input where $$$i^{th}$$$ input ($$$p_i$$$) indicates that there is an edge that connects node $$$i+1$$$ to node $$$p_i$$$ and all the edges also guarantee a tree (usually this comes with the $$$1 \leq p_i \leq i$$$ constraint to do that)? I personally prefer the latter.

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by CppC_solver (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by CppC_solver (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it +16 Vote: I do not like it

unrooted tree former, rooted tree latter. For rooted trees a lot of things (such as DP) get a much more easier implementation with the latter input. For unrooted trees I like to just treat them the same way as I do for usual undirected graphs

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

unrooted (first)