Add edges
for i in range ( N - 1 ) : NEW_LINE INDENT u = edges [ i ] [ 0 ] NEW_LINE v = edges [ i ] [ 1 ] NEW_LINE w = edges [ i ] [ 2 ] NEW_LINE adj [ u ] . append ( [ v , w ] ) NEW_LINE adj [ v ] . append ( [ u , w ] ) NEW_LINE DEDENT dfs ( R , 0 , K ) NEW_LINE