SHARE
TWEET

Hamilton

sepehr103 Jul 8th, 2015 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //c++11
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<cstdlib>
  6. #include<cassert>
  7. #include<stack>
  8. #include<cstring>
  9. #include<vector>
  10. #include<string>
  11. #include<cmath>
  12. #include<ctime>
  13. #include<set>
  14. #include<map>
  15. #include<queue>
  16. #include<fstream>
  17. #include<sstream>
  18. #include<iomanip>
  19. #include<complex>
  20.  
  21. #define mp make_pair
  22. #define X first
  23. #define Y second
  24. #define pb push_back
  25.  
  26. using namespace std;
  27.  
  28. typedef long long ll;
  29. typedef long double ld;
  30. typedef pair<int, int> pii;
  31. const ll MOD = 1e9 + 7;
  32. const double eps = 1e-7;
  33. const int maxN = 5e6 + 10;
  34. const int maxL = 45;
  35. const int inf = 1e9 + 10;
  36. bool adj[15][15];
  37. vector <int> P;
  38. int n, m;
  39.  
  40. inline bool call()
  41. {
  42.         if (!adj[P[0]][P.back()]) return false;
  43.         for (int i = 1; i < P.size(); i++)
  44.         {
  45.                 if (!adj[P[i]][P[i - 1]]) return false;
  46.         }
  47.         return true;
  48. }
  49.  
  50. inline void init()
  51. {
  52.         cin >> n >> m;
  53.         for (int i = 0, a, b; i < m; i++)
  54.         {
  55.                 cin >> a >> b; a--; b--;
  56.                 adj[a][b] = 1;
  57.                 adj[b][a] = 1;
  58.         }
  59.         for (int i = 0; i < n; i++)
  60.                 P.pb(i);
  61. }
  62.  
  63. inline void solve()
  64. {
  65.         bool res = call();
  66.         while (!res && next_permutation(P.begin(), P.end()))
  67.                 res = call();
  68.         if (res)
  69.                 for (int i = 0; i < n; i++)
  70.                         cout << P[i] << " ";
  71.         else cout << "NOT FOUND!";
  72.         cout << endl;
  73. }
  74.  
  75.  
  76. int main()
  77. {
  78.         //freopen("a.in", "r", stdin);
  79.         //freopen("a.out", "w", stdout);
  80.         ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
  81.         init();
  82.         solve();
  83.         //system("pause");
  84.         return 0;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top