Advertisement
prog3r

print

Jun 28th, 2025
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. //#include "testlib.h"
  2. #include <bits/extc++.h>
  3. using namespace std;
  4. using namespace __gnu_pbds;
  5. template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  6. #define int long long
  7. #define YES(x) cout << (x?"YES\n":"NO\n")
  8. #define NO(x) cout << (x?"NO\n":"YES\n")
  9. #ifdef LO
  10. #pragma GCC optimize("trapv")
  11. #endif
  12. #ifndef LO
  13. #pragma GCC optimize("Ofast,unroll-loops")
  14. #endif
  15. //constexpr int MOD = (119<<23)+1;
  16. //constexpr int MOD = 967276608647009887ll;
  17. //constexpr int MOD = 1e9+7;
  18. constexpr int INF = 1e18;
  19. signed main() {
  20. #ifndef LO
  21.     clog << "FIO\n";
  22.     ios::sync_with_stdio(0);
  23.     cin.tie(0);
  24. #endif
  25. #ifdef LO
  26.     cout << unitbuf;
  27. #endif
  28.     ifstream fin("nice.txt");
  29.     vector<int> dp(2);
  30.     vector<pair<int,int>> ch(2);
  31.     vector<int> palka(2);
  32.     for (int i = 2; ; i += 1) {
  33.         string s;
  34.         if (!getline(fin, s)) {
  35.             break;
  36.         }
  37.         dp.push_back({});
  38.         ch.push_back({});
  39.         palka.push_back({});
  40.         stringstream ss(s);
  41.         getline(ss, s, '(');
  42.         getline(ss, s, ',');
  43.         assert(stoi(s) == i);
  44.         getline(ss, s, ' ');
  45.         getline(ss, s, ' ');
  46.         dp[i] = stoi(s);
  47.         getline(ss, s, '|');
  48.         ch[i].first = stoi(s);
  49.         getline(ss, s, ' ');
  50.         getline(ss, s, '|');
  51.         ch[i].second = stoi(s);
  52.         getline(ss, s, ' ');
  53.         getline(ss, s);
  54.         palka[i] = stoi(s);
  55. //        cout << i << " " << dp[i] << " " << palka[i] << " " << ch[i].first << " " << ch[i].second << "\n";
  56.         assert(ss.eof());
  57.     }
  58.     cout << "MAX n: " << dp.size()-1 << "\n";
  59.     int curr = 1;
  60.     auto print = [&] (auto f, const int x) -> int {
  61.         assert(x < dp.size());
  62.         if (!x) {
  63.             return -1;
  64.         }
  65.         int U = curr++;
  66.         int u = U;
  67.         for (int i = 0; i < palka[x]-1; i += 1) {
  68.             int v = curr++;
  69.             cout << u << " " << v << "\n";
  70.             u = v;
  71.         }
  72.         int v1 = f(f, ch[x].first), v2 = f(f, ch[x].second);
  73.         if (v1 != -1) {
  74.             cout << u << " " << v1 << "\n";
  75.         }
  76.         if (v2 != -1) {
  77.             cout << u << " " << v2 << "\n";
  78.         }
  79.         return U;
  80.     };
  81.     int n;
  82.     while (cin >> n) {
  83.         cout << dp[n] << ":\n";
  84.         print(print, n);
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement