Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <vector>
- typedef std::vector<int> iVec;
- typedef std::vector<iVec> matr;
- static matr G;
- iVec obtain_cycle()
- {
- int i = 0;
- static int c = 0;
- const int n = G.size();
- iVec que(n);
- std::generate(que.begin(), que.end(), [] { return c++; });
- for (int k = 0; k < n * (n - 1); k++)
- {
- auto
- v0 = G[que[0]],
- v1 = G[que[1]];
- if (!v0[que[1]])
- {
- for (i = 2; !v0[que[i]] || !v1[que[i + 1]]; i++);
- std::reverse(que.begin() + 1, que.begin() + i);
- }
- que.push_back(std::forward<int>(que[0]));
- que.erase(que.begin());
- }
- return que;
- }
- template <class type>
- std::ostream& operator<<( std::ostream & Out, const std::vector<type> & Vec )
- {
- for (auto & a : Vec)
- Out << a + 1 << " ";
- return Out;
- }
- int main()
- {
- int n, is_e;
- std::ifstream infile("fullham.in");
- infile >> n;
- G = std::forward<matr>(matr(n, std::forward<iVec>(iVec(n , 0))));
- for (int u = 1; u < n; u++)
- for (int v = 0; v < u; v++)
- infile >> is_e, G[u][v] = G[v][u] = is_e;
- std::move(std::ofstream("fullham.out")) << obtain_cycle();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement