http://mirror.codeforces.com/contest/1074/submission/45462396 http://mirror.codeforces.com/contest/1074/submission/45462405
These two codes are exactly the same, except for this part:
In the Wrong answer on test 14 submission:
for (int i : inTree[rootp]) {
inTree[rootq].pb(i);
distToRoot[i] = distToRoot[i] ^ distToRoot[p] ^ edgeWeight ^ distToRoot[q];
root[i] = rootq;
}
In the Accepted submission:
edgeWeight ^= distToRoot[p] ^ distToRoot[q];
for (int i : inTree[rootp]) {
inTree[rootq].pb(i);
distToRoot[i] ^= edgeWeight;
root[i] = rootq;
}
(This is the end of the method, so xor-equals edgeWeight
shouldn't change anything later on.)
I thought xor sum is both commutative and associative? What's the difference between these two snippets? Am I missing something really obvious? Thanks in advance.