Source code for submission s633

FN.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.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9.  
  10. /*
  11.  * To change this template, choose Tools | Templates
  12.  * and open the template in the editor.
  13.  */
  14.  
  15. /**
  16.  *
  17.  * @author cteam94
  18.  */
  19. public class FN {
  20. Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
  21.  
  22. public static void main(String[] args) throws IOException {
  23.  
  24.  
  25. while((new FN()).readLine(br));
  26. }
  27.  
  28. public boolean readLine(BufferedReader br) throws IOException {
  29. String line = br.readLine();
  30. if (line == null) return false;
  31.  
  32. map = new HashMap<Integer, List<Integer>>();
  33.  
  34. String[] sp = line.split(" ");
  35. int n1 = Integer.parseInt(sp[0]);
  36. int n2 = Integer.parseInt(sp[1]);
  37.  
  38. for (int i = 1; i <= n1; i++) {
  39. map.put(i, new ArrayList<Integer>());
  40. }
  41.  
  42. for (int i = 0; i < n2; i++) {
  43. String ln = br.readLine();
  44. String[] sp2 = ln.split(" ");
  45. int u = Integer.parseInt(sp2[0]);
  46. int v = Integer.parseInt(sp2[1]);
  47.  
  48. List<Integer> l = map.get(u);
  49. l.add(v);
  50.  
  51. l = map.get(v);
  52. l.add(u);
  53. }
  54.  
  55. // System.out.println(map);
  56.  
  57. for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
  58. int c = 0;
  59. Integer integer = entry.getKey();
  60. List<Integer> list = entry.getValue();
  61. for (Integer v : list) {
  62. if (isPow(v)) c++;
  63. if (c >= 4) {
  64. System.out.println("YES");
  65. return true;
  66. }
  67. }
  68. }
  69. System.out.println("NO");
  70.  
  71. return true;
  72. }
  73.  
  74.  
  75. public boolean isPow(int x) {
  76. if (map.get(x).size() == 1) return true;
  77. return false;
  78. }
  79.  
  80.  
  81. }
  82.