Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- unordered_map<string, vector<string>> c;
- void generate(vector<string>& links, size_t pos, vector<string> built)
- {
- static int64_t longest = 0;
- if (pos < links.size())
- {
- generate(links, pos + 1, built);
- built.push_back(links[pos]);
- generate(links, pos + 1, built);
- return;
- }
- if (built.size() <= 2)
- return;
- for (size_t i = 0; i < built.size(); i++)
- for (size_t j = 0; j < built.size(); j++)
- {
- if (i == j)
- continue;
- if (find(c[built[i]].begin(), c[built[i]].end(), built[j]) == c[built[i]].end())
- return;
- }
- if (built.size() > longest)
- {
- longest = built.size();
- sort(built.begin(), built.end());
- for (size_t i = 0; i < built.size(); i++)
- cout << built[i] << (i == built.size() - 1 ? "" : ",");
- cout << endl;
- }
- }
- int main()
- {
- string line, c1, c2;
- ifstream inputfile("input.txt");
- while (getline(inputfile, line))
- {
- c1 = line.substr(0, 2), c2 = line.substr(3);
- if (find(c[c1].begin(), c[c1].end(), c2) == c[c1].end())
- c[c1].push_back(c2), c[c2].push_back(c1);
- }
- for (auto& it : c)
- generate(it.second, 0, vector<string>(1, it.first));
- inputfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement