Advertisement
limimage

EBAAAN

Mar 25th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 1e5 + 5;
  10.  
  11. int n, m, a, b, height[N], par[N], cur = 0;
  12. set<int> gr[N];
  13.  
  14. vector<int> cyc;
  15.  
  16. void dfs(int v = 1, int p = -1) {
  17. par[v] = p;
  18. if (p == -1)
  19. height[v] = 1;
  20. else
  21. height[v] = height[p] + 1;
  22. for (int u: gr[v]) {
  23. if (u != p) {
  24. if (height[u] == 0)
  25. dfs(u, v);
  26. else if (cur < height[v] - height[u] + 1) {
  27. cur = height[v] - height[u] + 1;
  28. cyc.clear();
  29. cyc.push_back(u);
  30. cyc.push_back(v);
  31. }
  32. }
  33. }
  34. }
  35.  
  36. void Solve() {
  37. //freopen("zhopa.txt", "r", stdin);
  38. unsigned seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
  39. mt19937 Mrand(seed);
  40. cin >> n >> m;
  41. while(m--) {
  42. cin >> a >> b;
  43. gr[a].insert(b);
  44. gr[b].insert(a);
  45. }
  46. int num = ceil(sqrt(n));
  47. dfs();
  48. if (cyc.size())
  49. while(par[cyc.back()] != cyc.front())
  50. cyc.push_back(par[cyc.back()]);
  51. if (cyc.size() >= num) {
  52. cout << 2 << endl << cyc.size() << endl;
  53. for (int ver: cyc) {
  54. cout << ver << " ";
  55. }
  56. return;
  57. }
  58. while(true) {
  59. vector<int> vec;
  60. set<int> st;
  61. int iter = 0;
  62. while(iter < n && vec.size() < num) {
  63. int v = (Mrand() % n) + 1;
  64. if (st.count(v) == 0 && gr[v].size() < n / 2 + vec.size()) {
  65. bool good = 1;
  66. for (int val: vec) {
  67. if (gr[v].count(val)) {
  68. good = 0;
  69. break;
  70. }
  71. }
  72. if (good) {
  73. vec.push_back(v);
  74. st.insert(v);
  75. }
  76. iter++;
  77. }
  78. }
  79. if (vec.size() == num) {
  80. cout << 1 << endl;
  81. for (int val: vec) {
  82. cout << val << " ";
  83. }
  84. return;
  85. }
  86. }
  87. }
  88.  
  89. int main() {
  90. ios::sync_with_stdio(false);
  91. cin.tie(nullptr);
  92. cout.tie(nullptr);
  93.  
  94. //auto start = chrono::high_resolution_clock::now();
  95. Solve();
  96. //auto end = chrono::high_resolution_clock::now();
  97. //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement