We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I see two ambiguties in this problem formulation, please correct me if I am wrong.
It is, to me and also to @Shubham_2012 not clearly defined how to interpret which node is the i:th. is it the i:th node that we encountered during parsing or is it the one with the i:th value, starting from whatever the root node's offset is?
Edges are bi-directional as per the problem formulation ("In each of the next N-1 lines, there are two space separated integers(a b) representing an edge from node a to Node b and vice-versa.", emphasis added). This means that there is no discernable difference between parent and child nodes. To see why this matters, say that I pick a node at random and call it the root of my subtree. Since all edges connected to it are bi-directional, even what we in some configuration could have regarded as the node's parent is also a child node. This means that, in essence, every subtree is the entire tree, only with a different root node. And so, the answer for how many colors there are should always be the same. Obviously, this cannot be correct, can it?
P.S. Why does the commenting system here on hackerrank say that markdown is supported when it only works in the preview window?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Coloring Tree
You are viewing a single comment's thread. Return to all comments →
I see two ambiguties in this problem formulation, please correct me if I am wrong.
Edges are bi-directional as per the problem formulation ("In each of the next N-1 lines, there are two space separated integers(a b) representing an edge from node a to Node b and vice-versa.", emphasis added). This means that there is no discernable difference between parent and child nodes. To see why this matters, say that I pick a node at random and call it the root of my subtree. Since all edges connected to it are bi-directional, even what we in some configuration could have regarded as the node's parent is also a child node. This means that, in essence, every subtree is the entire tree, only with a different root node. And so, the answer for how many colors there are should always be the same. Obviously, this cannot be correct, can it?
P.S. Why does the commenting system here on hackerrank say that markdown is supported when it only works in the preview window?