Advertisement
GerONSo

Untitled

Aug 30th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. /*
  2. --┬-- | | --┬-- | |
  3. | |\ | | | |
  4. | | \ | | -----> | |
  5. | | \ | | | |
  6. | | \ | | | |
  7. --┴-- | \| | └---- └----
  8.  
  9. */
  10.  
  11. #define pragma
  12.  
  13. #ifdef pragma
  14. #pragma GCC optimize("Ofast")
  15. #pragma GCC optimize("no-stack-protector")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17. #pragma GCC optimize("unroll-loops")
  18. #endif // pragma
  19.  
  20. #include<bits/stdc++.h>
  21.  
  22. #define ll long long
  23. #define all(x) begin(x),end(x)
  24. #define pb push_back
  25. #define x first
  26. #define y second
  27. #define int long long
  28.  
  29. using namespace std;
  30.  
  31. typedef vector<int> vi;
  32. typedef vector<bool> vb;
  33. typedef pair<int,int> pii;
  34. typedef long double ld;
  35. typedef vector<vi> matrix;
  36.  
  37. const int INF = 1e9 + 7;
  38. const int MAXN = 1e6 + 7;
  39. const ld EPS = 1e-9;
  40. const ld PI = atan2(0, -1);
  41.  
  42. void seriy() {
  43. ios::sync_with_stdio(0);
  44. cin.tie(0);
  45. cout.tie(0);
  46. // cout << fixed << setprecision(6);
  47. #if _android
  48. freopen("input", "r", stdin);
  49. freopen("output", "w", stdout);
  50. #endif
  51. }
  52.  
  53. struct pt {
  54. int x, y;
  55. };
  56.  
  57. istream& operator>>(istream& is, pt& p) {
  58. is >> p.x >> p.y;
  59. return is;
  60. }
  61.  
  62. ostream& operator<<(ostream& os, pt& p) {
  63. os << p.x << " " << p.y;
  64. return os;
  65. }
  66.  
  67. matrix g;
  68. vector<pt> ans, tans;
  69. vi used;
  70.  
  71. void dfs(int u, int dep) {
  72. used[u] = 1;
  73. for(auto v : g[u]) {
  74. if(!used[v] && dep < 2) {
  75. tans.pb({u + 1, v + 1});
  76. dfs(v, dep + 1);
  77. }
  78. }
  79. }
  80.  
  81. signed main() {
  82. seriy();
  83. int n, m;
  84. cin >> n >> m;
  85. g.resize(n);
  86. used.resize(n);
  87. map<pii, bool> no;
  88. for(int i = 0; i < m; i++) {
  89. int u, v;
  90. cin >> u >> v;
  91. u--;
  92. v--;
  93. no[{u, v}] = 1;
  94. no[{v, u}] = 1;
  95. }
  96. for(int i = 0; i < n; i++) {
  97. for(int j = i + 1; j < n; j++) {
  98. if(!no[{i, j}] && !no[{j, i}]) {
  99. g[i].pb(j);
  100. g[j].pb(i);
  101. }
  102. }
  103. }
  104. int mn = INF;
  105. for(int i = 0; i < n; i++) {
  106. used.assign(n, 0);
  107. tans.clear();
  108. queue<pii> q;
  109. q.push({i, 0});
  110. used[i] = 1;
  111. while(!q.empty()) {
  112. pii u = q.front();
  113. q.pop();
  114. for(auto v : g[u.x]) {
  115. if(!used[v] && u.y < 2) {
  116. tans.pb({u.x + 1, v + 1});
  117. used[v] = 1;
  118. q.push({v, u.y + 1});
  119. }
  120. }
  121. }
  122. if(accumulate(all(used), 0) == n && tans.size() < mn) {
  123. mn = tans.size();
  124. }
  125. }
  126. for(int i = 0; i < n; i++) {
  127. used.assign(n, 0);
  128. tans.clear();
  129. queue<pii> q;
  130. q.push({i, 0});
  131. used[i] = 1;
  132. while(!q.empty()) {
  133. pii u = q.front();
  134. q.pop();
  135. for(auto v : g[u.x]) {
  136. if(!used[v] && u.y < 2) {
  137. tans.pb({u.x + 1, v + 1});
  138. used[v] = 1;
  139. q.push({v, u.y + 1});
  140. }
  141. }
  142. }
  143. cout << accumulate(all(used), 0) << '\n';
  144. if(accumulate(all(used), 0) == n && tans.size() == mn) {
  145. cout << tans.size() << '\n';
  146. for(auto i : tans) {
  147. cout << i << '\n';
  148. }
  149. return 0;
  150. }
  151. }
  152.  
  153. return 0;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement