Source code for submission s591

Go to diff to previous submission

fn.cpp

  1. #include<iostream>
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. #include<math.h>
  7.  
  8. #include<vector>
  9. #include<set>
  10.  
  11. using namespace std;
  12.  
  13. #define FOR(i,a,b) for(int i=a; i<=b; i++)
  14.  
  15. #define PII pair<int, int>
  16. #define MP make_pair
  17. #define PB push_back
  18.  
  19. #define SIZE(s) ((int)(s).size())
  20.  
  21. #define ll long long
  22.  
  23. #define MAX 10047
  24.  
  25. int N, M;
  26. vector<int> G[MAX];
  27.  
  28. int colors[MAX];
  29. int color;
  30.  
  31. void dfs(int v)
  32. {
  33. colors[v] = color;
  34. FOR(i,0, SIZE(G[v])-1)
  35. {
  36. int u = G[v][i];
  37. if (colors[u] == 0)
  38. dfs(u);
  39. }
  40. }
  41.  
  42. int V[MAX];
  43.  
  44. int st4[MAX];
  45. vector<int> st3[MAX];
  46.  
  47. //skusime medzi dvoma vrcholmi
  48. bool skus(int v1, int v2)
  49. {
  50. // cout << v1 << " " << v2 << endl;
  51. set<int> vrchols;
  52. FOR(i,0, SIZE(G[v1])-1) if (G[v1][i] != v2) vrchols.insert( G[v1][i] );
  53. FOR(i,0, SIZE(G[v2])-1) if (G[v2][i] != v1) vrchols.insert( G[v2][i] );
  54. return SIZE(vrchols) >= 4;
  55. }
  56.  
  57. int main()
  58. {
  59. int a, b;
  60. while(scanf("%d %d",&N, &M)== 2)
  61. {
  62. FOR(i,0,N-1) G[i].clear();
  63. FOR(i,0,N-1) V[i] = 0;
  64. while(M--)
  65. {
  66. scanf("%d %d",&a,&b);
  67. a--; b--;
  68. G[a].PB(b);
  69. G[b].PB(a);
  70. V[a]++;
  71. V[b]++;
  72. }
  73.  
  74. color = 0;
  75. FOR(i,0,N-1) colors[i] = 0;
  76. FOR(i,0,N-1)
  77. {
  78. if (colors[i] == 0)
  79. {
  80. color++;
  81. dfs(i);
  82. }
  83. }
  84.  
  85. // FOR(i,0,N-1) cout << colors[i] << endl;
  86.  
  87. bool ok = false;
  88. FOR(c,1,color)
  89. {
  90. st4[c] = 0;
  91. st3[c].clear();
  92. }
  93. FOR(i,0,N-1)
  94. {
  95. if (V[i] > 3)
  96. st4[ colors[i] ]++;
  97. if (V[i] > 2)
  98. st3[ colors[i] ].PB(i);
  99. }
  100.  
  101. FOR(c,1,color)
  102. {
  103. if (st4[c] >= 1) ok = true;
  104. if (SIZE(st3[c]) > 1)
  105. {
  106. FOR(i,0, SIZE( st3[c])-1)
  107. FOR(j, i+1 , SIZE(st3[c])-1)
  108. {
  109. if (skus( st3[c][i], st3[c][j])) ok = true;
  110. }
  111. }
  112. }
  113.  
  114. if (ok) puts("YES");
  115. else puts("NO");
  116. }
  117. return 0;
  118. }
  119.  
  120.  

Diff to submission s528

fn.cpp

--- c5.s528.cteam079.fn.cpp.0.fn.cpp
+++ c5.s591.cteam079.fn.cpp.0.fn.cpp
@@ -7,4 +7,5 @@
 
 #include<vector>
+#include<set>
 
 using namespace std;
@@ -42,5 +43,15 @@
 
 int st4[MAX];
-int st3[MAX];
+vector<int> st3[MAX];
+
+//skusime medzi dvoma vrcholmi
+bool skus(int v1, int v2)
+{
+//      cout << v1 << " " << v2 << endl;
+        set<int> vrchols;
+        FOR(i,0, SIZE(G[v1])-1) if (G[v1][i] != v2) vrchols.insert( G[v1][i] );
+        FOR(i,0, SIZE(G[v2])-1) if (G[v2][i] != v1) vrchols.insert( G[v2][i] );
+        return SIZE(vrchols) >= 4;
+}
 
 int main()
@@ -78,5 +89,5 @@
                 {
                         st4[c] = 0;
-                        st3[c] = 0;                     
+                        st3[c].clear();
                 }
                 FOR(i,0,N-1)
@@ -85,5 +96,5 @@
                                 st4[ colors[i] ]++;
                         if (V[i] > 2)
-                                st3[ colors[i] ]++;
+                                st3[ colors[i] ].PB(i);
                 }
 
@@ -91,5 +102,12 @@
                 {
                         if (st4[c] >= 1) ok = true;
-                        if (st3[c] >= 2) ok = true;
+                        if (SIZE(st3[c]) > 1)
+                        {
+                                FOR(i,0, SIZE( st3[c])-1)
+                                        FOR(j, i+1 , SIZE(st3[c])-1)
+                                        {
+                                                if (skus( st3[c][i], st3[c][j])) ok = true;
+                                        }
+                        }
                 }