loop for all neighbors except parent and aggregate Sum over all subtrees
for i in range ( len ( edge [ u ] ) ) : NEW_LINE INDENT v = edge [ u ] [ i ] NEW_LINE if ( v != parent ) : NEW_LINE INDENT dfs ( v , u , totalSum , edge , subtree , res ) NEW_LINE Sum += subtree [ v ] NEW_LINE DEDENT DEDENT