Getting WA in Pairing, Unable to find bug

link: https://ide.codingblocks.com/s/249835

I have applied bfs to count the number of elements in every component of the graph.

Try using multiply mod function written below for multiplication.It might be possible it is due to overflow on multiplication.
ll mulmod(ll a, ll b, ll mod)

{

ll res = 0; // Initialize result

a = a % mod;

while (b > 0)

{

// If b is odd, add 'a' to result

if (b % 2 == 1)

res = (res + a) % mod;

// Multiply 'a' with 2

a = (a * 2) % mod;

// Divide b by 2

b /= 2;

}

// Return result

return res % mod;

}

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.