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