I am facing problem in this question https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/practice-problems/algorithm/little-shino-and-k-ancestor-57fdef57/description/.
What I did differently from editorial was just placed that line “ans[color[ele]].pb(ele);” as soon as i enter the dfs function instead of that !visited block. The result should be same with a slight change in base condition that now i have to access"res[ele]=ans[color[ele]][size-k-1];" instead of “res[ele]=ans[color[ele]][size-k];” because now i am inserting earlier as soon as dfs function starts.
I am getting some of tc as wrong. Can someone please help me. Thanks in advance
My solution https://ideone.com/XepUmh