Source code for submission s1075

fn.java

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.regex.Pattern;
  7.  
  8.  
  9. public class fn {
  10.  
  11. private static class V{
  12. List<Integer> s;
  13. boolean n;
  14.  
  15. public V() {
  16. n = false;
  17. s = new ArrayList<Integer>();
  18. }
  19.  
  20. }
  21.  
  22. public static void main(String[] args) throws IOException {
  23. Pattern p=Pattern.compile("\\s");
  24. String line;
  25. while((line=buf.readLine())!=null){
  26. String[] vstup = p.split(line);
  27. int m = Integer.parseInt(vstup[0]);
  28. int n = Integer.parseInt(vstup[1]);
  29. V[] graf = new V[m+1];
  30. for(int i=1; i<=m; i++){
  31. graf[i] = new V();
  32. }
  33. for(int i=0; i<n; i++){
  34. line = buf.readLine();
  35. vstup = p.split(line);
  36. int a = Integer.parseInt(vstup[0]);
  37. int b = Integer.parseInt(vstup[1]);
  38. graf[a].s.add(b);
  39. graf[b].s.add(a);
  40. }
  41. boolean res = false;
  42. for(int i=1; i<=m; i++){
  43. if(graf[i].s.size()==4){
  44. boolean vysl = true;
  45. for(int sus: graf[i].s){
  46. vysl = vysl && graf[sus].s.size()==1;
  47. }
  48. res = res || vysl;
  49. }
  50. }
  51. System.out.println(res ? "YES" : "NO");
  52.  
  53. }
  54. }
  55.  
  56. }
  57.