fork download
  1. import java.util.Scanner;
  2. class Main {
  3. private static Scanner in;
  4. public static void main(String args[]){
  5. in = new Scanner(System.in);
  6. int testcases = in.nextInt();
  7.  
  8.  
  9. for (int i = 0; i < testcases; i++)
  10. {
  11.  
  12. long Wl = in.nextLong();
  13. long Dl = in.nextLong();
  14. long Wr = in.nextLong();
  15. long Dr = in.nextLong();
  16.  
  17.  
  18. if(recursive(Wl)*Dl == recursive(Wr)*Dr){
  19. System.out.println("YES");
  20. }
  21. else{
  22. System.out.println("NO");
  23. }
  24.  
  25. // if (i != testcases) { System.out.println("");}
  26.  
  27. }
  28. }
  29.  
  30.  
  31. private static long recursive(long weight){
  32. in = new Scanner(System.in);
  33. if(weight == 0){
  34. long Wl = in.nextLong();
  35. long Dl = in.nextLong();
  36. long Wr = in.nextLong();
  37. long Dr = in.nextLong();
  38. Wl = recursive(Wl);
  39. Wr = recursive(Wr);
  40.  
  41. if(Wl*Dl == Wr*Dr){
  42. return Wl+Wr;
  43. }
  44. else{
  45. return -1000;
  46. }
  47. }
  48.  
  49. else{
  50. return weight;
  51. }
  52. }
  53.  
  54.  
  55. }
Runtime error #stdin #stdout #stderr 0.1s 380608KB
stdin
1

0 2 0 4
0 3 0 1
1 1 1 1
2 4 4 2
1 6 3 2
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextLong(Scanner.java:2265)
	at java.util.Scanner.nextLong(Scanner.java:2225)
	at Main.recursive(Main.java:34)
	at Main.main(Main.java:18)