Weird xor error?

Revision en1, by farmersrice, 2018-11-09 05:19:56

http://codeforces.net/contest/1074/submission/45462396 http://codeforces.net/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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English farmersrice 2018-11-09 05:21:48 0 Tiny change: '45462396\nhttp://c' -> '45462396\n\nhttp://c' (published)
en2 English farmersrice 2018-11-09 05:21:39 2 Tiny change: '45462396\nhttp://c' -> '45462396\n\nhttp://c' (saved to drafts)
en1 English farmersrice 2018-11-09 05:19:56 872 Initial revision (published)