Mark each node by its DFS counter/root. For each query check if the marks of both nodes are same or not.

Time complexity: O(n+m+q)

Statistics

76% Solution Ratio
fsshakkhorEarliest, Dec '18
Kuddus.6068Fastest, 0.0s
nusuBotLightest, 4.9 MB
foyaz05Shortest, 697B
Toph uses cookies. By continuing you agree to our Cookie Policy.