n nodes numbered 0 to n - 1; edges[i] = [u, v] is an edge between u and v. Node i holds the number values[i], and you also get a key.
You may repeat the following any number of times, including zero: pick any edge [u, v] and replace both numbers at its ends, values[u] = values[u] XOR key and values[v] = values[v] XOR key.
Return the largest total of all node values you can reach.values=[4, 1, 6], key=5, edges=[[0, 1], [1, 2]] → 11
Toggling turns 4 → 1, 1 → 4, 6 → 3. Only the middle one pays off, yet nodes always change in pairs. Toggling edge (0, 1) gives [1, 4, 6], the same sum 11 as doing nothing; nothing beats it.
values=[10, 10], key=1, edges=[[0, 1]] → 22
One toggle gives [11, 11], sum 22.
values=[1, 2, 3, 0], key=6, edges=[[0, 1], [0, 2], [0, 3]] → 22
values=[4, 1, 6], key=5, edges=[[0, 1], [1, 2]]
11
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.