Source code for submission s984

Go to diff to previous submission

Fn.java

  1.  
  2. import java.util.*;
  3.  
  4. /**
  5.  *
  6.  * @author cteam039
  7.  */
  8. public class Fn {
  9.  
  10. public static void main(String... args) {
  11. int points, lines;
  12. Scanner scan = new Scanner(System.in);
  13. while (scan.hasNextInt()) {
  14. iteration(scan);
  15.  
  16. }
  17. }
  18.  
  19. public static void iteration(Scanner scan) {
  20. int points, lines;
  21.  
  22. points = scan.nextInt();
  23. lines = scan.nextInt();
  24. List<List<Graph>> graphs = new ArrayList<List<Fn.Graph>>();
  25. if (points < 2 || lines < 1) {
  26. System.out.println("NO");
  27. return;
  28. }
  29. for (int i = 0; i < lines; i++) {
  30. int a = scan.nextInt();
  31. int b = scan.nextInt();
  32.  
  33. List<List<Graph>> sets = new ArrayList<List<Graph>>();
  34. boolean added = false;
  35. for(List<Graph> graph : graphs){
  36.  
  37. added = insert(graph, new Graph(a), new Graph(b));
  38.  
  39. if(added){
  40. sets.add(graph);
  41. }
  42. }
  43. if(!added){
  44. List<Graph> gr= new ArrayList<Graph>();
  45. graphs.add(gr);
  46. gr.add(new Graph(a));
  47. gr.add(new Graph(b));
  48. }
  49. else if(sets.size() > 1) {
  50. for(int j = 1; j < sets.size(); j++){
  51. for(Graph g : sets.get(j)){
  52. if(!sets.get(0).contains(g)){
  53. sets.get(0).add(g);
  54. }
  55. }
  56. graphs.remove(sets.get(j));
  57.  
  58. }
  59. int counter = 0;
  60. for(Graph g: sets.get(0)){
  61. if(g.incide == 1){
  62. counter ++;
  63. }
  64. }
  65. if(counter > 3 ){
  66. System.out.println("YES");
  67. return;
  68. }
  69. }
  70. }
  71.  
  72. for(List<Graph> list : graphs){
  73. int counter = 0;
  74. for(Graph g: list){
  75. if(g.incide == 1){
  76. counter ++;
  77. }
  78. }
  79. if(counter > 3 ){
  80. System.out.println("YES");
  81. return;
  82. }
  83. }
  84. System.out.println("NO");
  85.  
  86. }
  87.  
  88. public static boolean insert(List<Graph> graph, Graph a, Graph b){
  89. if(graph.contains(a)){
  90. if(graph.contains(b)){
  91. return true;
  92. }
  93. else{
  94. graph.get(graph.indexOf(a)).incide++;
  95. graph.add(b);
  96. return true;
  97. }
  98. }
  99. else{
  100. if(graph.contains(b)){
  101. graph.get(graph.indexOf(b)).incide++;
  102. graph.add(a);
  103. return true;
  104. }
  105. else{
  106. return false;
  107. }
  108. }
  109. }
  110.  
  111. private static class Graph {
  112.  
  113. int id;
  114. int incide;
  115.  
  116. public Graph(int id) {
  117. this.id = id;
  118. incide = 1;
  119. }
  120.  
  121. @Override
  122. public boolean equals(Object arg0) {
  123. if(!(arg0 instanceof Graph)){
  124. return false;
  125. }
  126. return ((Graph)arg0).id == id;
  127. }
  128.  
  129. @Override
  130. public int hashCode() {
  131. int hash = 5;
  132. hash = 79 * hash + this.id;
  133. return hash;
  134. }
  135.  
  136.  
  137. }
  138. }
  139.  

Diff to submission s973

Fn.java

--- c5.s973.cteam039.fn.java.0.Fn.java
+++ c5.s984.cteam039.fn.java.0.Fn.java
@@ -57,4 +57,14 @@
                     
                 }
+                int counter = 0;
+            for(Graph g: sets.get(0)){
+                if(g.incide == 1){
+                    counter ++;
+                }
+            }
+            if(counter > 3 ){
+                System.out.println("YES");
+                return;
+            }
             }
         }