Go to diff to previous submission
#include <iostream> #include <vector> using namespace std; struct Point{ int m_counter; vector<short> m_points; Point(){ m_counter = 0; } }; int main(void){ int points, lines; while(cin >> points >> lines){ Point ** p_points = new Point* [points]; for(int i = 0; i < points ; i++){ p_points[i] = NULL; } short first, second; for(int i = 0; i < lines ; i++){ cin >> first >> second; first--; second--; if(p_points[first]){ p_points[first]->m_counter++; p_points[first]->m_points.push_back(second); } else{ p_points[first] = new Point(); p_points[first]->m_counter = 1; p_points[first]->m_points.push_back(second); } if(p_points[second]){ p_points[second]->m_counter++; p_points[second]->m_points.push_back(first); } else{ p_points[second] = new Point(); p_points[second]->m_counter = 1; p_points[second]->m_points.push_back(first); } } bool isBunny = false; for(int i = 0; i < points ; i++){ if(p_points[i] && p_points[i]->m_counter==4){ bool found = true; for(int j = 0; j < p_points[i]->m_points.size(); j++){ if(p_points[ p_points[i]->m_points[j] ]->m_counter != 1){ found = false; break; } } if(found) { cout << "YES" << endl; goto konec; } } } cout << "NO" << endl; konec: ; } return 0; }
--- c5.s913.cteam009.fn.cpp.0.fn.cpp +++ c5.s1078.cteam009.fn.cpp.0.otherBunny.cpp @@ -1,68 +1,69 @@ -#include<iostream> -#include<vector> +#include <iostream> +#include <vector> using namespace std; -struct Point { - unsigned counter; - vector<short> points; - - Point() { - counter = 0; +struct Point{ + int m_counter; + vector<short> m_points; + Point(){ + m_counter = 0; } }; -Point ** graph; -unsigned N; - -inline bool isPaw(unsigned point) { - return (graph[point]->counter == 1); -} - -bool isBunny(unsigned point) { - for(vector<short>::iterator it = graph[point]->points.begin(); it != graph[point]->points.end(); ++it) { - if(!isPaw(*it)) - return false; - } - return true; -} - -int main() { - unsigned points; - unsigned lines; - while(cin >> points >> lines) { - graph = new Point * [points]; - for (unsigned i = 0; i < points; i++) { - graph[i] = new Point(); +int main(void){ + int points, lines; + while(cin >> points >> lines){ + Point ** p_points = new Point* [points]; + for(int i = 0; i < points ; i++){ + p_points[i] = NULL; } - for (unsigned i = 0; i < lines; i++) { - unsigned x, y; - cin >> x >> y; - graph[x-1]->points.push_back(y-1); - graph[y-1]->points.push_back(x-1); - graph[x-1]->counter++; - graph[y-1]->counter++; - } - - N = points; + short first, second; + for(int i = 0; i < lines ; i++){ + cin >> first >> second; + first--; + second--; + if(p_points[first]){ + p_points[first]->m_counter++; + p_points[first]->m_points.push_back(second); + } + else{ + p_points[first] = new Point(); + p_points[first]->m_counter = 1; + p_points[first]->m_points.push_back(second); + } - bool found = false; - for (unsigned i = 0; i < N; i++) { - if(graph[i]->counter == 4 && isBunny(i)) { - cout << "YES" << endl; - found = true; - break; + if(p_points[second]){ + p_points[second]->m_counter++; + p_points[second]->m_points.push_back(first); + } + else{ + p_points[second] = new Point(); + p_points[second]->m_counter = 1; + p_points[second]->m_points.push_back(first); } } - if (!found) - cout << "NO" << endl; + bool isBunny = false; - for (unsigned i = 0; i < points; i++) { - delete graph[i]; + for(int i = 0; i < points ; i++){ + if(p_points[i] && p_points[i]->m_counter==4){ + bool found = true; + for(int j = 0; j < p_points[i]->m_points.size(); j++){ + if(p_points[ p_points[i]->m_points[j] ]->m_counter != 1){ + found = false; + break; + } + } + if(found) { + cout << "YES" << endl; + goto konec; + } + } } - delete [] graph; + cout << "NO" << endl; + konec: + ; } - return 0; }