Hello codeforces community , i am getting TLE . My logic is : First i store those edges node to set those which color are different , then i put a simple dfs on each of the node stored in set which will be exact for root i break the loop and print it . If i aint found a node , print no . Now I understand for which case i got TLE . If i can stop calling dfs again and again , i can reduce TLE . But can find the logic .
think stupid
why bro ? I just shared my idea .
first of all, you need a vis array for your dfs function
second, you don't have to check all the edges with different colors, it's enough to check only the nodes of one of this edges, then you get the result.
You don't need a visited array, because it's a tree, just enough to check a parent.
second,
Yes you are right, I didn't notice that his code deals with the parent...