When v and u are on the same level but are in different subtree . Now move both u and v up by 1 till they are not same
while ( v != u ) { if ( prime [ weight [ v ] ] ) count ++ ; if ( prime [ weight [ u ] ] ) count ++ ; u = par [ u ] ; v = par [ v ] ; }