You have seen rerooting with sums and counts. This problem combines subtree DP with rerooting in a slightly different way.
Each node is colored black or white. For each node v, find the maximum value of (white nodes minus black nodes) over all connected subtrees containing v.
Think: First solve for a fixed root. What is the optimal subtree value for each node? Then think about how to reroot. The subtree DP value at each node is the best contribution from below, clamped to zero if negative.