Source code for submission s563

Go to diff to previous submission

fn.cpp

  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <set>
  6. #include <map>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. vector< set<int> > G;
  14. vector< int > C;
  15. int N, M;
  16. while(scanf("%d %d", &N, &M) == 2)
  17. {
  18. G = vector< set<int> >(N);
  19. C = vector< int >(N);
  20. for(int i=0; i<N; i++)
  21. {
  22. G[i] = set<int>();
  23. C[i] = 0;
  24. }
  25. for(int i=0; i<M; i++)
  26. {
  27. int x, y;
  28. scanf("%d %d", &x, &y);
  29. --x;
  30. --y;
  31. G[x].insert(y);
  32. G[y].insert(x);
  33. C[x]++;
  34. C[y]++;
  35. }
  36. bool ok = false;
  37. for(int i=0; i<N; i++)
  38. {
  39. if(G[i].size() >= 4)
  40. {
  41. puts("YES");
  42. ok = true;
  43. break;
  44. }
  45. }
  46. if(!ok)
  47. puts("NO");
  48. }
  49.  
  50. return 0;
  51. }
  52.  

Diff to submission s454

fn.cpp

--- c5.s454.cteam036.fn.cpp.0.fn.cpp
+++ c5.s563.cteam036.fn.cpp.0.fn.cpp
@@ -11,14 +11,14 @@
 int main()
 {
-        vector< vector<int> > G;
+        vector< set<int> > G;
         vector< int > C;
         int N, M;
         while(scanf("%d %d", &N, &M) == 2)
         {
-                G = vector< vector<int> >(N);
+                G = vector< set<int> >(N);
                 C = vector< int >(N);
                 for(int i=0; i<N; i++)
                 {
-                        G[i] = vector<int>();
+                        G[i] = set<int>();
                         C[i] = 0;
                 }
@@ -29,6 +29,6 @@
                         --x;
                         --y;
-                        G[x].push_back(y);
-                        G[y].push_back(x);
+                        G[x].insert(y);
+                        G[y].insert(x);
                         C[x]++;
                         C[y]++;
@@ -37,5 +37,5 @@
                 for(int i=0; i<N; i++)
                 {
-                        if(C[i] >= 4)
+                        if(G[i].size() >= 4)
                         {
                                 puts("YES");