Source code for submission s927

Go to diff to previous submission

Main.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8.  
  9. public class Main {
  10. private static String str;
  11.  
  12.  
  13. public static void main(String[] args) throws IOException {
  14. while ((str = reader.readLine()) != null) {
  15. String[] tmp = str.split(" ");
  16. int numPoints = Integer.parseInt(tmp[0]);
  17. int numLines = Integer.parseInt(tmp[1]);
  18. List<Point> points = new ArrayList<Point>();
  19. for (int i = 0; i < numLines; i++) {
  20. String tmp2[] = reader.readLine().split(" ");
  21. int x = Integer.parseInt(tmp2[0]);
  22. int y = Integer.parseInt(tmp2[1]);
  23. points.add(new Point(x, y));
  24. points.add(new Point(y, x));
  25. }
  26. boolean correct = false;
  27. boolean keepLoop = true;
  28. for (int i = 0; i < points.size(); i++) {
  29. Point point = points.get(i);
  30. point.connections++;
  31. for (int j = i; j < points.size(); j++) {
  32. Point point2 = points.get(j);
  33. if (point2.number == point.number && point2.connectedWith != point.connectedWith) {
  34. point.connections += 1;
  35. if (point.connections == 4) {
  36. correct = true;
  37. keepLoop = false;
  38. break;
  39. }
  40. }
  41. }
  42. if (!keepLoop) break;
  43. }
  44.  
  45. // for (int i = 0; i < points.size(); i++) {
  46. // if (points.get(i).getConnections() == 4) {
  47. // correct=true;
  48. // }
  49. // }
  50. if (correct) {
  51. System.out.println("YES");
  52. } else {
  53. System.out.println("NO");
  54. }
  55. }
  56. }
  57.  
  58. static class Point {
  59. int number = 0;
  60. int connectedWith = 0;
  61. int connections = 0;
  62.  
  63. public Point(int number, int connectedWith) {
  64. this.number = number;
  65. this.connectedWith = connectedWith;
  66. }
  67.  
  68. void setConnections(int connections) {
  69. this.connections = connections;
  70. }
  71.  
  72. int getConnections() {
  73. return this.connections;
  74. }
  75. }
  76. }
  77.  

Diff to submission s915

Main.java

--- c5.s915.cteam061.fn.java.0.Main.java
+++ c5.s927.cteam061.fn.java.0.Main.java
@@ -25,4 +25,6 @@
                 points.add(new Point(y, x));
             }
+            boolean correct = false;
+            boolean keepLoop = true;
             for (int i = 0; i < points.size(); i++) {
                 Point point = points.get(i);
@@ -32,14 +34,19 @@
                     if (point2.number == point.number && point2.connectedWith != point.connectedWith) {
                         point.connections += 1;
+                        if (point.connections == 4) {
+                            correct = true;
+                            keepLoop = false;
+                            break;
+                        }
                     }
                 }
-                System.out.println(point.connections);
-            }
-            boolean correct = false;
-            for (int i =0; i < points.size(); i++) {
-                if (points.get(i).getConnections() == 4) {
-                    correct=true;
-                }
+                if (!keepLoop) break;
             }
+            
+//            for (int i = 0; i < points.size(); i++) {
+//                if (points.get(i).getConnections() == 4) {
+//                    correct=true;
+//                }
+//            }
             if (correct) {
                 System.out.println("YES");