Source code for submission s1069

all.cpp

  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <queue>
  10. #include <set>
  11. #include <sstream>
  12. #include <stack>
  13. #include <string>
  14. #include <utility>
  15. #include <vector>
  16. using namespace std;
  17.  
  18. #define DEBUG(x) cerr << ">> " << #x << ": " << x << endl;
  19. #define REP(i,a) for (int i =0; i < (a);++i)
  20. #define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
  21.  
  22. int num, edgecount;
  23. int* degrees;
  24.  
  25. int main() {
  26.  
  27. while (scanf("%d%d", &num, &edgecount) != EOF)
  28. {
  29. degrees = new int[num];
  30. for (int j = 0; j < num; j++)
  31. {
  32. degrees[j] = 0;
  33. }
  34. for (int i = 0; i < edgecount; i++)
  35. {
  36. int from, to;
  37. scanf("%d%d", &from, &to);
  38. degrees[from-1]++;
  39. degrees[to-1]++;
  40. }
  41. int deg4 = 0;
  42. int deg3 = 0;
  43. int deg2 = 0;
  44. int deg1 = 0;
  45. for (int j = 0; j < num; j++)
  46. {
  47. switch(degrees[j])
  48. {
  49. case 1: deg1++; break;
  50. case 2: deg2++; break;
  51. case 3: deg3++; break;
  52. case 4: deg4++; break;
  53. default: deg4++; break;
  54. }
  55. }
  56. if (deg4 > 0) { printf("YES\n"); }
  57. else if (deg3 < 0) { printf("NO\n"); }
  58. else
  59. {
  60. if (deg3 >= 2) { printf("YES\n"); } else { printf("NO\n"); }
  61. }
  62.  
  63. delete[] degrees;
  64. }
  65.  
  66. return 0;
  67. }