You are given an integer n representing the number of nodes in an undirected tree, with nodes numbered from n edges where edges[i] good of size n where good[i] i is good, and good[i] i is bad.
The score of a connected subgraph is calculated as the count of good nodes minus the count of bad nodes contained within that subgraph.
Return an array ans of size n where ans[i] is the maximum score among all connected subgraphs containing node i.
Constraints:
n
edges.length n
edges[i]
n
good.length n
good[i]
The input is generated such that edges represents a valid tree.
You are given an integer n representing the number of nodes in an undirected tree, with nodes numbered from n edges where edges[i] good of size n where good[i] i is good, and good[i] i is bad.
The score of a connected subgraph is calculated as the count of good nodes minus the count of bad nodes contained within that subgraph.
Return an array ans of size n where ans[i] is the maximum score among all connected subgraphs containing node i.
Constraints:
n
edges.length n
edges[i]
n
good.length n
good[i]
The input is generated such that edges represents a valid tree.