Go to diff to previous submission
#include<iostream> #include<vector> using namespace std; struct Point { unsigned counter; vector<short> points; Point() { counter = 0; } }; Point ** graph; unsigned N; inline bool isPaw(unsigned point) { return (graph[point]->counter == 1); } bool isBunny(unsigned point) { int paws = 0; for(vector<short>::iterator it = graph[point]->points.begin(); it != graph[point]->points.end(); ++it) { if(isPaw(*it)) { paws++; } else return false; } return paws >= 4; } 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(); } for (unsigned i = 0; i < lines; i++) { unsigned x, y; cin >> x >> y; graph[x-1]->points.push_back(y-1); graph[x-1]->counter++; graph[y-1]->points.push_back(y-1); graph[y-1]->counter++; } N = points; bool found = false; for (unsigned i = 0; i < N; i++) { if(graph[i]->counter >= 4 && isBunny(i)) { cout << "YES" << endl; found = true; break; } } if (!found) cout << "NO" << endl; for (unsigned i = 0; i < points; i++) { delete graph[i]; } delete [] graph; } return 0; }
--- c5.s1078.cteam009.fn.cpp.0.otherBunny.cpp +++ c5.s1088.cteam009.fn.cpp.0.fn.cpp @@ -1,69 +1,72 @@ -#include <iostream> -#include <vector> +#include<iostream> +#include<vector> using namespace std; -struct Point{ - int m_counter; - vector<short> m_points; - Point(){ - m_counter = 0; +struct Point { + unsigned counter; + vector<short> points; + + Point() { + 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; +Point ** graph; +unsigned N; + +inline bool isPaw(unsigned point) { + return (graph[point]->counter == 1); +} + +bool isBunny(unsigned point) { + int paws = 0; + for(vector<short>::iterator it = graph[point]->points.begin(); it != graph[point]->points.end(); ++it) { + if(isPaw(*it)) { + paws++; + } else + return false; + } + return paws >= 4; +} + +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(); } - 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); - } + for (unsigned i = 0; i < lines; i++) { + unsigned x, y; + cin >> x >> y; + graph[x-1]->points.push_back(y-1); + graph[x-1]->counter++; + + graph[y-1]->points.push_back(y-1); + graph[y-1]->counter++; + } + + N = points; - 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 found = false; + for (unsigned i = 0; i < N; i++) { + if(graph[i]->counter >= 4 && isBunny(i)) { + cout << "YES" << endl; + found = true; + break; } } - bool isBunny = false; + if (!found) + cout << "NO" << endl; - 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; - } - } + for (unsigned i = 0; i < points; i++) { + delete graph[i]; } - cout << "NO" << endl; - konec: - ; + delete [] graph; } + return 0; }