# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4152 | 2013-09-02T14:50:13 Z | gudbooy | Cactus? Not cactus? (kriii1_C) | C++ | 0 ms | 0 KB |
#include<iostream> #include<string.h> #include<string> #include<vector> #include<iterator> #include<algorithm> #include<map> #include<set> #include<stack> #include<queue> #include<functional> #include<cmath> using namespace std; #define NM 100000 int nm[NM][2]; int N, M; vector<pair<int, int>> diff; bool cacus() { for(int i=0; i<diff.size(); i++) { for(int j=i+1; j<diff.size(); j++) { int index_i = diff[i].second; int index_j = diff[j].second; if(nm[index_i][0] == nm[index_j][1] || nm[index_i][1] == nm[index_j][0]) return true; } } return false; } void test() { int result=0; cin >> N >> M; for(int i=0; i<M; i++) { cin >> nm[i][0] >> nm[i][1]; if(abs(nm[i][0]-nm[i][1]) > 1) diff.push_back(make_pair(nm[i][0]-nm[i][1], i)); } if(cacus()) cout << "Not cactus" << endl; else cout << "Cactus" << endl; } int main() { test(); return 0; }