3812. Minimum Edge Toggles on a Tree
You are given an undirected tree with
nnodes, numbered from 0 ton - 1. It is represented by a 2D integer arrayedges of lengthn - 1, whereedges[i] = [a_i, b_i]indicates that there is an edge between nodesa_iandb_iin the tree.You are also given two binary strings
startandtargetof lengthn. For each nodex,start[x]is its initial color andtarget[x]is its desired color.In one operation, you may pick an edge with index
iand toggleboth of its endpoints. That is, if the edge is[u, v], then the colors of nodesuandveach flip from'0'to'1'or from'1'to'0'.Return an array of edge indices whose operations transform
startintotarget. Among all valid sequences with minimum possible length, return the edge indices in increasing order.If it is impossible to transform
startintotarget, return an array containing a single element equal to -1.
1 |
|