Make diameter of tree equals to d
for i in range ( d ) : NEW_LINE INDENT deg [ i ] += 1 NEW_LINE deg [ i + 1 ] += 1 NEW_LINE if ( deg [ i ] > k or deg [ i + 1 ] > k ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE return NEW_LINE DEDENT DEDENT