#include #include #include using namespace std; using custom_map_t = map>; vector usedPoints(0); static bool isInside(custom_map_t& map, const size_t& key) { return map.find(key) != map.end(); } static bool isUsed(const size_t& key) { for (auto& jt : usedPoints) { if (jt == key) { return true; } } return false; } static bool isFound(custom_map_t& map, const size_t& lookingIn, const size_t& lookingFor) { usedPoints.push_back(lookingIn); for (auto& it : map[lookingIn]) { if (it == lookingFor) { usedPoints.clear(); return true; } if (!isUsed(it)) { return isFound(map, it, lookingFor); } } usedPoints.clear(); return false; } int main() { size_t pairAmount; custom_map_t pointMap; cout << "Enter the amount of pairs you want to enter later: "; cin >> pairAmount; cout << endl << "Enter pairs: " << endl; for (size_t i = 0, first, second; i < pairAmount; i++) { cout << i + 1 << ") "; cin >> first >> second; if (isInside(pointMap, first) || isInside(pointMap, second)) { if (isFound(pointMap, first, second)) { cout << "Already in" << endl; } else { cout << "Not found" << endl; pointMap[first].push_back(second); pointMap[second].push_back(first); } } else { cout << "First time see" << endl; pointMap[first].push_back(second); pointMap[second].push_back(first); } } return 0; }