Difficulty in building up the logic

Hi, actually I was trying one question where we are given with 2 arrays :-
parent=[]
size=[]
where parent[i] gives the parent index of any node in a tree and size gives the corresponding node’s size. So, we have to cut the branch between any parent and child which will give us 2 separate trees and these 2 trees total size sum must have the minimum difference possible. For eg: - If we have parent=[-1,0,0,1,1,2] and size=[1,2,2,1,1,1] It means that a node having -1 as it’s parent (which means it’s the parent node) has a size of 1. And similarly we have other elements as well.
For this case we can cut the branch between the root node and it’s left child as the 2 separate trees will have a size of 4.

I understood the question, but not able to form the logic. Can anyone plz help with this question ?