Source code for submission s640

Go to diff to previous submission

fn.cpp

  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cmath>
  4. #include <complex>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <iomanip>
  8. #include <iostream>
  9. #include <list>
  10. #include <map>
  11. #include <queue>
  12. #include <set>
  13. #include <sstream>
  14. #include <stack>
  15. #include <string>
  16. #include <utility>
  17.  
  18. using namespace std;
  19.  
  20. #define DEBUG(x) cout << ">>> " << #x << " : " << x << endl;
  21. #define REP(i,a) for (int i = 0; i < (a); ++i)
  22. #define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
  23. #define FORD(i,a,b) for (int i = (a); i >= (b); --i)
  24. inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
  25. const int INF = 1<<29;
  26.  
  27. typedef long long ll;
  28.  
  29. #define maxN 10005
  30.  
  31. int n,m;
  32. int x,y;
  33. vector<int> edges[maxN];
  34. bool found2;
  35. bool visited[maxN];
  36. bool diff;
  37. bool ok;
  38.  
  39. vector<int> th,paw;
  40.  
  41. void comp(int u){
  42. if(visited[u]) return;
  43. visited[u]=true;
  44. if(edges[u].size()>=4) found2=true;
  45. if(edges[u].size()==3 && !found2){
  46. REP(i,th.size()){
  47. diff = 0;
  48. REP(j,3){
  49. if(edges[th[i]][j]==u) continue;
  50. ok=true;
  51. REP(k,3){
  52. if(edges[th[i]][j]==edges[u][k]) ok=false;
  53. }
  54. if(ok) diff++;
  55. }
  56. if(diff>=2){ found2=true; break; }
  57. }
  58. th.push_back(u);
  59.  
  60. }
  61. REP(i,edges[u].size()){
  62. comp(edges[u][i]);
  63. }
  64. }
  65.  
  66. int main() {
  67. while(scanf("%d%d",&n,&m)==2){
  68. REP(i,n) edges[i].clear();
  69. REP(i,n) visited[i]=false;
  70. found2=false;
  71. REP(i,m){
  72. scanf("%d%d",&x,&y);
  73. x--; y--;
  74. edges[x].push_back(y);
  75. edges[y].push_back(x);
  76. }
  77. REP(i,n){
  78. th.clear();
  79. comp(i);
  80. }
  81. if(found2) printf("YES\n");
  82. else printf("NO\n");
  83.  
  84. }
  85.  
  86. return 0;
  87. }
  88.  

Diff to submission s593

fn.cpp

--- c5.s593.cteam010.fn.cpp.0.fn.cpp
+++ c5.s640.cteam010.fn.cpp.0.fn.cpp
@@ -32,6 +32,10 @@
 int x,y;
 vector<int> edges[maxN];
-bool found,found2;
+bool found2;
 bool visited[maxN];
+bool diff;
+bool ok;
+
+vector<int> th,paw;
 
 void comp(int u){
@@ -39,6 +43,20 @@
         visited[u]=true;
         if(edges[u].size()>=4) found2=true;
-        if(edges[u].size()==3 && found) found2=true;
-        if(edges[u].size()==3) found=true;
+        if(edges[u].size()==3 && !found2){
+                REP(i,th.size()){
+                        diff = 0;
+                        REP(j,3){
+                                if(edges[th[i]][j]==u) continue;
+                                ok=true;
+                                REP(k,3){
+                                        if(edges[th[i]][j]==edges[u][k]) ok=false;
+                                }
+                                if(ok) diff++;
+                        }
+                        if(diff>=2){ found2=true; break; }
+                }
+                th.push_back(u);
+
+        }
         REP(i,edges[u].size()){
                 comp(edges[u][i]);
@@ -50,5 +68,5 @@
                 REP(i,n) edges[i].clear();
                 REP(i,n) visited[i]=false;
-                found=found2=false;
+                found2=false;
                 REP(i,m){
                         scanf("%d%d",&x,&y);
@@ -58,5 +76,5 @@
                 }
                 REP(i,n){
-                        found=false;
+                        th.clear();
                         comp(i);
                 }