Comments

How do you solve the problem when the graph is a tree? (Subtask 3)

Right now it doesn't allow to make any submissions, it shows "Unexpected error". What happened?

Problem B was annoying :(

Does this mean that if a and b are even and d is odd then it should have no solution It's incorrect. There is a solution.

If $$$a$$$ and $$$b$$$ are even, then their LSB of both are greater than 1.

If $$$d$$$ is odd, then its LSB is 1.

$$$min(1, 1) \lt 1$$$ Isn't true. Hence, there is a solution.

If you are confused with the fact that if $$$min(lsb(a), lsb(b)) \lt lsb(d)$$$, then there is no solution., read below.

Let $$$dq$$$ be any multiple of $$$d$$$. And $$$k = lsb(d)$$$. You can see that $$$lsb(dq) \geq lsb(d)$$$. It can be easily seen by adding d itself in its binary representation. You can see that any multiple of $$$d$$$ will have its bits on after or from $$$lsb(d)$$$.

Let $$$m = a|x$$$. According to the problem, we require $$$m$$$ to be some multiple of $$$d$$$. Since $$$m$$$ will be forced to have on all bits that are on in $$$a$$$ or $$$x$$$, then $$$m$$$ will have the $$$lsb(a)$$$ bit on. But we have seen that any multiple of $$$d$$$ will have its bits on from or after its lsb. Hence, if $$$lsb(a) \lt lsb(d)$$$, then there is no solution, it's impossible to have any multiple of $$$d$$$ that can have the $$$lsb(a)$$$ on, since it's less than $$$lsb(d)$$$.

So if $$$lsb(a) \lt lsb(d)$$$ or $$$lsb(b) \lt lsb(d)$$$, then there is no solution.

I have the same problem.

I guess it's because of problems with the Codeforces API.