Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cctype>
  5. #include <cstring>
  6. #include <ctime>
  7.  
  8. #include <iostream>
  9. #include <algorithm>
  10. #include <vector>
  11. #include <deque>
  12. #include <list>
  13. #include <set>
  14. #include <map>
  15. #include <queue>
  16. #include <stack>
  17. #include <string>
  18.  
  19. using namespace std;
  20.  
  21. #define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
  22. #define mp make_pair
  23. #define vi vector<int>
  24. #define vvi vector<vector<int>>
  25. #define vvvi vector<vector<vector<int>>>
  26. #define pb push_back
  27. #define li long long
  28.  
  29. #define geta(_type, _x, _n)\
  30. vector<_type> _x(_n);\
  31. for (int _i = 0; _i < _n; ++_i)\
  32. cin >> _x[_i];
  33.  
  34. vector<set<int>> a;
  35. set<int> compsub;
  36. int ans = 0;
  37. set<int> compsub_ans;
  38.  
  39. void gen(set<int> candidates, set<int> used)
  40. {
  41. while (!candidates.empty())
  42. {
  43. set<int>::iterator it = candidates.begin();
  44. compsub.insert(*it);
  45. set<int> n_candidates;
  46. set<int> n_used;
  47.  
  48. for (set<int>::iterator it2 = candidates.begin(); it2 != candidates.end(); it2++)
  49. if (a[(*it2)].find(*it) != a[(*it2)].end())
  50. n_candidates.insert(*it2);
  51.  
  52. if (!used.empty())
  53. {
  54. for (set<int>::iterator it2 = used.begin(); it2 != used.end(); it2++)
  55. if (a[(*it2)].find(*it) != a[(*it2)].end())
  56. n_used.insert(*it2);
  57. }
  58.  
  59. if (n_candidates.empty() && n_used.empty())
  60. {
  61. if (compsub.size() > ans)
  62. ans = compsub.size(), compsub_ans = compsub;
  63. }
  64. else
  65. gen(n_candidates, n_used);
  66.  
  67. used.insert(*it);
  68. compsub.erase(*it);
  69. candidates.erase(it);
  70. }
  71. }
  72.  
  73. bool is_click(set<int> click)
  74. {
  75. if (click.empty())
  76. return true;
  77. for (set<int>::iterator it = click.begin(); it != click.end(); it++)
  78. for (set<int>::iterator it2 = click.begin(); it2 != click.end(); it2++)
  79. if ((it != it2) && (a[(*it)].find(*it2) == a[(*it)].end()))
  80. return false;
  81.  
  82. return true;
  83. }
  84.  
  85.  
  86. void check_click(set<int> click)
  87. {
  88. forn (i, a.size())
  89. {
  90. set<int> click2 = click;
  91. if (click2.find(i) == click2.end())
  92. {
  93. click2.insert(i);
  94. if (is_click(click2))
  95. {
  96. if (click2.size() > ans)
  97. ans = click2.size(), compsub_ans = click2;
  98. check_click(click2);
  99. }
  100. }
  101. }
  102. }
  103.  
  104. int main()
  105. {
  106. #ifdef _DEBUG
  107. freopen("input.txt", "r", stdin);
  108. freopen("output.txt", "w", stdout);
  109. #endif
  110. int n, m;
  111. cin >> n >> m;
  112. a.resize(n);
  113. set<int> candidates;
  114. set<int> used;
  115.  
  116. forn(i, n)
  117. candidates.insert(i);
  118.  
  119. forn(i, m)
  120. {
  121. int x, y;
  122. cin >> x >> y;
  123. x--, y--;
  124. a[x].insert(y);
  125. a[y].insert(x);
  126. }
  127.  
  128. gen(candidates, used);
  129. cout << "Приближенное вычисление: " << endl << "Размер максимальной клики: " << ans << endl << "Клика: ";
  130. for (set<int>::iterator it = compsub_ans.begin(); it != compsub_ans.end(); it++)
  131. cout << (*it) + 1 << ' ';
  132. cout << endl << endl;
  133.  
  134. set<int> new_st;
  135. check_click(new_st);
  136. cout << "Точное вычисление: " << endl << "Размер максимальной клики: " << ans << endl << "Клика: ";
  137. for (set<int>::iterator it = compsub_ans.begin(); it != compsub_ans.end(); it++)
  138. cout << (*it) + 1 << ' ';
  139. return !(cout << endl);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement