Advertisement
Guest User

Untitled

a guest
May 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. const int n = 32;
  7.  
  8. bool has_zero_preneighbors(int** G, int v) {
  9. for (int i = 0; i < n; i++)
  10. if (G[i][v] > 0)
  11. return false;
  12. return true;
  13. }
  14.  
  15. bool has_hamilton_path_mutha_fucka(int** G) {
  16. queue<int> q;
  17. int res[n];
  18. int ri = 0;
  19.  
  20. for (int v = 0; v < n; v++)
  21. if (has_zero_preneighbors(G, v))
  22. q.push(v);
  23.  
  24. while (!q.empty()) {
  25. int v = q.front(); q.pop();
  26. res[ri++] = v;
  27.  
  28. for (int u = 0; u < n; u++)
  29. if (G[v][u] > 0) {
  30. G[v][u] = -1; // żeby nie robić dodatkowych macierzy itp.
  31. if (has_zero_preneighbors(G, u))
  32. q.push(u);
  33. }
  34. }
  35.  
  36. if (ri < n)
  37. return false;
  38.  
  39. for (int i = 0; i < n-1; i++)
  40. if (G[res[i]][res[i+1]] == 0)
  41. return false;
  42. return true;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement