I solved the problem using DSU; My logic: let suppose there is two disjoint set of size M and N where each member is a friend of every other in the set. now suppose one member of 1st set become friend of a member of 2nd set. we need total of m*n such friendship for every member of 1st set to become friends with every other member of 2nd set.
is there any mistake in my logic ?(posting me solution just for logic not for debugging)
thanks in advance
int z = siz[root(a)]*siz[root(b)];
There is integer overflow here. Here is an accepted solution: 25713608
thanks for quick reply. now i will have a sound sleep.