Source code for submission s915

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. for (int i = 0; i < points.size(); i++) {
  27. Point point = points.get(i);
  28. point.connections++;
  29. for (int j = i; j < points.size(); j++) {
  30. Point point2 = points.get(j);
  31. if (point2.number == point.number && point2.connectedWith != point.connectedWith) {
  32. point.connections += 1;
  33. }
  34. }
  35. System.out.println(point.connections);
  36. }
  37. boolean correct = false;
  38. for (int i =0; i < points.size(); i++) {
  39. if (points.get(i).getConnections() == 4) {
  40. correct=true;
  41. }
  42. }
  43. if (correct) {
  44. System.out.println("YES");
  45. } else {
  46. System.out.println("NO");
  47. }
  48. }
  49. }
  50.  
  51. static class Point {
  52. int number = 0;
  53. int connectedWith = 0;
  54. int connections = 0;
  55.  
  56. public Point(int number, int connectedWith) {
  57. this.number = number;
  58. this.connectedWith = connectedWith;
  59. }
  60.  
  61. void setConnections(int connections) {
  62. this.connections = connections;
  63. }
  64.  
  65. int getConnections() {
  66. return this.connections;
  67. }
  68. }
  69. }
  70.