danielvitor23

D. Delivery

Sep 13th, 2023
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pb push_back
  5. #define all(x) x.begin(),x.end()
  6. #define rall(x) x.rbegin(),x.rend()
  7. using namespace std;
  8. using ii = pair<int, int>;
  9. using i64 = long long;
  10. const int INF = 0x3f3f3f3f;
  11. const i64 INFLL = 0x3f3f3f3f3f3f3f3f;
  12.  
  13. int main() {
  14.   cin.tie(0)->sync_with_stdio(0);
  15.  
  16.   int l, s; cin >> l >> s;
  17.   if (l == s and l == 1) {
  18.     cout << "2 1\n1 2\n";
  19.     return 0;
  20.   }
  21.  
  22.   if (2*s < l or s > l) {  
  23.     cout << "-1\n";
  24.     return 0;
  25.   }
  26.  
  27.   if (s + 1 == l) {
  28.     if (l == 2) {
  29.       cout << "4 4\n";
  30.       cout << "1 2\n";
  31.       cout << "2 3\n";
  32.       cout << "2 4\n";
  33.       cout << "3 4\n";
  34.       return 0;
  35.     }
  36.     int qtdCycle = 2 * l - 2;
  37.  
  38.     cout << 1 + qtdCycle << ' ' << 1 + qtdCycle << '\n';
  39.     for (int u = 1; u <= qtdCycle; ++u) {
  40.       if (u == qtdCycle) {
  41.         cout << qtdCycle << ' ' << "1\n";
  42.         continue;
  43.       }
  44.       cout << u << ' ' << u+1 << '\n';
  45.     }
  46.     cout << qtdCycle+1 << ' ' << "1\n";
  47.  
  48.     return 0;
  49.   }
  50.  
  51.   if (s == (l+1)/2) {
  52.     cout << l+1 << ' ' << l << '\n';
  53.     for (int i = 0; i < l; ++i) {
  54.       cout << i+1 << ' ' << i+2 << '\n';
  55.     }
  56.   } else if (s == l) {
  57.     int qtdCycle = 2 * l;
  58.  
  59.     cout << qtdCycle << ' ' << qtdCycle << '\n';
  60.     for (int u = 1; u <= qtdCycle; ++u) {
  61.       if (u == qtdCycle) {
  62.         cout << qtdCycle << ' ' << "1\n";
  63.         continue;
  64.       }
  65.       cout << u << ' ' << u+1 << '\n';
  66.     }
  67.   } else {
  68.     int qtdNodes = 2 * s + 2 * (l - s) - 1;
  69.  
  70.     vector<ii> edges;
  71.     for (int u = 1; u <= 2 * s; ++u) {
  72.       if (u == 2*s) {
  73.         edges.push_back({u, 1});
  74.       } else {
  75.         edges.push_back({u, u+1});
  76.       }
  77.     }
  78.  
  79.     int delta = 2 * s;
  80.     if (s != l) {
  81.       edges.push_back({1, delta+1});
  82.     }
  83.     for (int u = 1; u < 2*(l-s); ++u) {
  84.       if (u == 2*(l-s)-1) {
  85.         // cout << delta+u << ' ' << "1\n";
  86.         edges.push_back({delta+u, 1});
  87.       } else {
  88.         // cout << delta+u << ' ' << delta+u+1 << '\n';
  89.         edges.push_back({delta+u, delta+u+1});
  90.       }
  91.     }
  92.  
  93.     cout << qtdNodes << ' ' << edges.size() << '\n';
  94.     for (auto [a, b] : edges) {
  95.       cout << a << ' ' << b << '\n';
  96.     }
  97.   }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment