fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int []freq = new int[1000001];
  11. public static void solveXorGame(int []a, int []b, int n) {
  12. for(int i=0;i<1000001;i++) freq[i] = 0;
  13. for(int i=0;i<n;i++) freq[b[i]]++;
  14. int xorValue = 0;
  15. for(int i=0;i<n;i++) {
  16. xorValue ^= a[i]; xorValue ^= b[i];
  17. }
  18. int []c = new int[n];
  19. for(int i=0;i<n;i++){
  20. c[i] = a[i]^xorValue;
  21. if(freq[c[i]] == 0){ System.out.println(-1); return; }
  22. freq[c[i]]--;
  23. }
  24. for(int i=0;i<n;i++) System.out.format("%d ", c[i]);
  25. System.out.println(); return;
  26. }
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. Scanner scan = new Scanner(System.in);
  30. int testcases = scan.nextInt();
  31. while(testcases-- > 0) {
  32. int n = scan.nextInt();
  33. int []a = new int[n];
  34. int []b = new int[n];
  35. for(int i=0;i<n;i++) a[i] = scan.nextInt();
  36. for(int i=0;i<n;i++) b[i] = scan.nextInt();
  37. solveXorGame(a, b, n);
  38. }
  39. }
  40. }
Success #stdin #stdout 0.13s 56284KB
stdin
2
5
3 1 2 4 5
2 4 5 1 3
5
3 1 2 4 5
2 4 5 1 3
stdout
3 1 2 4 5 
3 1 2 4 5