When computing up[v] for child of node , you need the combined contribution of all other children of , excluding . If has children, recomputing the combination for each child takes per child and total.
The fix: build prefix and suffix arrays over 's children. prefix[i] combines children through . suffix[i] combines children through . To exclude child , combine prefix[i-1] with suffix[i+1] in . This keeps the total work per node proportional to its degree, giving overall.