codeDominus's blog

By codeDominus, history, 7 years ago, In English

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

Tags dsu
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
7 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

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

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

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    thanks for quick reply. now i will have a sound sleep.