Closest Watched Node on a Network Route

You operate the observatory desk of a nationwide relay network. The network grew without any redundancy, so it is a tree with n hubs numbered 0 to n - 1, rooted at hub 0, which acts as the gateway. The links are given as edges, where edges[i] = [ui, vi] describes a bidirectional fiber link between hubs ui and vi. Because the topology is a tree, exactly one simple route connects any pair of hubs.

Every hub streams telemetry upward along its parent links until it reaches the gateway. Hub x watches over hub y when x appears somewhere on the telemetry chain of y, meaning on the path from y up to hub 0. Every hub also watches over itself.

You are given queries, where queries[i] = [starti, endi, watchi]. For each query, consider the traffic route from starti to endi. Among all hubs v on that route for which watchi watches over v, report the hub closest to watchi, measured in hops along the network. If no hub on the route is watched over by watchi, report -1 for that query.

Return an array answer where answer[i] is the result for queries[i].

Examples
Input: [[[0,1],[0,2],[1,3],[1,4],[2,5]],[[3,4,1],[4,5,0],[3,5,4],[4,5,1],[3,3,2]]]
Output: [1,0,-1,1,-1]
Hints

Closest Watched Node on a Network Route

You operate the observatory desk of a nationwide relay network. The network grew without any redundancy, so it is a tree with `n` hubs numbered `0` to `n - 1`, rooted at hub `0`, which acts as the gateway. The links are given as `edges`, where `edges[i] = [ui, vi]` describes a bidirectional fiber link between hubs `ui` and `vi`. Because the topology is a tree, exactly one simple route connects any pair of hubs.