You are given an integer n representing the number of nodes labeled from edges of directed edges where each edges[i] = [u_i, v_i] indicates a one way edge from u_i to v_i.
If you ignore edge directions, the underlying graph forms a tree. For each node x, determine the minimum number of edges that must be reversed so that starting from x, it is possible to reach every other node by following directed edges.
Return an array answer of length n where answer[x] is this minimum number of reversals for node x.
Note: Reversing an edge changes its direction from
u -> vtov -> u.
Constraints:
n
edges.length n
edges[i].length
u_i edges[i][0] n
v_i edges[i][1] n
u_i v_i
The input is generated such that if all edges were treated as bidirectional, the graph would be a tree.
You are given an integer n representing the number of nodes labeled from edges of directed edges where each edges[i] = [u_i, v_i] indicates a one way edge from u_i to v_i.
If you ignore edge directions, the underlying graph forms a tree. For each node x, determine the minimum number of edges that must be reversed so that starting from x, it is possible to reach every other node by following directed edges.
Return an array answer of length n where answer[x] is this minimum number of reversals for node x.
Note: Reversing an edge changes its direction from
u -> vtov -> u.
Constraints:
n
edges.length n
edges[i].length
u_i edges[i][0] n
v_i edges[i][1] n
u_i v_i
The input is generated such that if all edges were treated as bidirectional, the graph would be a tree.