Go to diff to previous submission
#include <iostream> #include <vector> #include <cstdio> #include <cmath> #include <set> #include <map> #include <string> using namespace std; int main() { vector< set<int> > G; vector< int > C; int N, M; while(scanf("%d %d", &N, &M) == 2) { G = vector< set<int> >(N); C = vector< int >(N); for(int i=0; i<N; i++) { G[i] = set<int>(); C[i] = 0; } for(int i=0; i<M; i++) { int x, y; scanf("%d %d", &x, &y); --x; --y; G[x].insert(y); G[y].insert(x); C[x]++; C[y]++; } bool ok = false; for(int i=0; i<N; i++) { if(G[i].size() >= 4) { puts("YES"); ok = true; break; } } if(!ok) puts("NO"); } return 0; }
--- 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");