Go to diff to previous submission
#include<iostream> using namespace std; bool ** graph; unsigned * connections; unsigned N; inline bool isPaw(unsigned point) { return (connections[point] == 1); } bool isBunny(unsigned point) { short paws = 0; for(unsigned i = 0; i < N; i++) { if(graph[point][i] == 1) { if(isPaw(graph[point][i])) { if(++paws > 4) { return false; } } } } if (paws == 4) return true; else return false; } int main() { unsigned points; unsigned lines; while(cin >> points >> lines) { graph = new bool * [points]; for (unsigned i = 0; i < points; i++) { graph[i] = new bool [points]; for (unsigned j = 0; j < points; j++) { graph[i][j] = false; } } connections = new unsigned [points]; for (unsigned i = 0; i < points; i++) connections[i] = 0; for (unsigned i = 0; i < lines; i++) { unsigned x, y; cin >> x >> y; graph[x-1][y-1] = true; graph[y-1][x-1] = true; connections[x-1]++; connections[y-1]++; } N = points; bool found = false; for (unsigned i = 0; i < N; i++) { if(connections[i] == 4 && isBunny(i)) { cout << "YES" << endl; found = true; break; } } if (!found) cout << "NO" << endl; delete [] connections; for (unsigned i = 0; i < points; i++) { delete [] graph[i]; } delete [] graph; } return 0; }
--- c5.s832.cteam009.fn.cpp.0.fn.cpp +++ c5.s867.cteam009.fn.cpp.0.fn.cpp @@ -2,28 +2,10 @@ using namespace std; -short * paws; bool ** graph; unsigned * connections; unsigned N; -bool isPaw(unsigned point) { - if(paws[point] != -1) - return (bool) paws[point]; - else { - bool con = false; - for(unsigned i = 0; i < N; i++) { - if(graph[point][i] == 1) { - if (con) { - paws[point] = 0; - return false; - } else { - con = true; - } - } - } - - paws[point] = 1; - return true; - } +inline bool isPaw(unsigned point) { + return (connections[point] == 1); } @@ -57,8 +39,4 @@ } } - - paws = new short [points]; - for (unsigned i = 0; i < points; i++) - paws[i] = -1; connections = new unsigned [points]; @@ -89,5 +67,4 @@ cout << "NO" << endl; - delete [] paws; delete [] connections;