Блог пользователя codeDominus

Автор codeDominus, история, 7 лет назад, По-английски

link to problem

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)

my solution

thanks in advance

Теги dsu
  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

int z = siz[root(a)]*siz[root(b)];

There is integer overflow here. Here is an accepted solution: 25713608