fork download
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4.  
  5. public class OddEvenTree {
  6.  
  7. public int[] getTree(String[] dist)
  8. {
  9. int[] noSolution = new int[1];
  10. noSolution[0] = -1;
  11.  
  12. int n = dist.length;
  13. int[] d = new int[n];
  14. List<Integer> part0 = new ArrayList<Integer>(), part1 = new ArrayList<Integer>();
  15. for(int i = 0; i < n; i++)
  16. if(dist[0].charAt(i) == 'E') {
  17. d[i] = 0;
  18. part0.add(i);
  19. }
  20. else {
  21. d[i] = 1;
  22. part1.add(i);
  23. }
  24. if(d[0] == 1)
  25. return noSolution;
  26. if(part0.size() == 0 || part1.size() == 0)
  27. return noSolution;
  28. for(int i = 0; i < n; i++)
  29. for(int j = 0; j < n; j++)
  30. {
  31. int shouldBe = (d[i] + d[j]) % 2;
  32. if(shouldBe == 0 && dist[i].charAt(j) == 'O')
  33. return noSolution;
  34. if(shouldBe == 1 && dist[i].charAt(j) == 'E')
  35. return noSolution;
  36. }
  37.  
  38. int[] ret = new int[(n-1)*2];
  39. int p = 0;
  40. for(int i = 0; i < part1.size(); i++)
  41. {
  42. ret[p] = part0.get(0);
  43. p ++;
  44. ret[p] = part1.get(i);
  45. p ++;
  46. }
  47. for(int i = 1; i < part0.size(); i++)
  48. {
  49. ret[p] = part0.get(i);
  50. p ++;
  51. ret[p] = part1.get(0);
  52. p ++;
  53. }
  54. return ret;
  55. }
  56.  
  57. }
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class OddEvenTree is public, should be declared in a file named OddEvenTree.java
public class OddEvenTree {
       ^
1 error
stdout
Standard output is empty