3373. Maximize the Number of Target Nodes After Connecting Trees II
There exist two undirected trees with
nandmnodes, labeled from[0, n - 1]and[0, m - 1], respectively.You are given two 2D integer arrays
edges1andedges2of lengthsn - 1andm - 1, respectively, whereedges1[i] = [ai, bi]indicates that there is an edge between nodesaiandbiin the first tree andedges2[i] = [ui, vi]indicates that there is an edge between nodesuiandviin the second tree.Node
uis target to nodevif the number of edges on the path fromutovis even. Note that a node is always target to itself.Return an array of
nintegersanswer, whereanswer[i]is the maximum possible number of nodes that are target to nodeiof the first tree if you had to connect one node from the first tree to another node in the second tree.Note that queries are independent from each other. That is, for every query you will remove the added edge before proceeding to the next query.
1 | class Solution { |