malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, INF = 0X3F3F3F3F;   int n, tot;   char s[N];   vector<int> ans;   set<int> s1, s2;   int main() {     scanf( %s , s + 1), n = strlen(s + 1);     for (int i = (1); i <= (n); ++i) {       if (s[i] ==  L )         s1.insert(i);       else         s2.insert(i);     }     s1.insert(INF), s2.insert(INF);     if (make_pair(-((int)(s1).size()), *s1.begin()) >         make_pair(-((int)(s2).size()), *s2.begin()))       swap(s1, s2);     int go = *s1.begin();     for (int i = (1); i <= (n); ++i) {       if (i & 1) {         if (go == INF || (*s2.lower_bound(go) == INF && *s1.begin() != go &&                           *s1.begin() < *s2.begin())) {           ++tot;           go = *s1.begin();         }         s1.erase(go);         ans.push_back(go);         go = *s2.lower_bound(go);       } else {         if (go == INF || (*s1.lower_bound(go) == INF && *s2.begin() != go &&                           *s2.begin() < *s1.begin())) {           ++tot;           go = *s2.begin();         }         s2.erase(go);         ans.push_back(go);         go = *s1.lower_bound(go);       }     }     printf( %d n , tot);     for (auto x : ans) printf( %d  , x);     return 0;   }
#include <iostream>   #include <vector>   #include <array>   #define vi vector<int>   #define pii pair<int, int>   #define fst first   #define snd second      using namespace std;      const int SZ = (1 << 19) + 5, INF = (1e9) + 7;      int N, ans[200001];   vi idx[200001];      array<int, 4> seg[2][SZ];   int lz[2][SZ];      array<int, 4> merge(const array<int, 4>& L, const array<int, 4>& R)   {    return {min(L[0], R[0]), max(L[1], R[1]), min(L[2], R[2]), max(L[3], R[3])};   }      inline void prop(int t, int idx, int L, int R)   {    if (lz[t][idx])    {     for (int i = 0; i < 4; i++)      {      if (seg[t][idx][i] > -INF && seg[t][idx][i] < INF) seg[t][idx][i] += lz[t][idx];     }     if (L < R)     {      lz[t][2 * idx] += lz[t][idx];      lz[t][2 * idx + 1] += lz[t][idx];     }     lz[t][idx] = 0;    }   }      void build(int t, int idx, int L, int R)   {    seg[t][idx][0] = seg[t][idx][2] = INF;    seg[t][idx][1] = seg[t][idx][3] = -INF;    if (L == R)     {     seg[t][idx][(L & 1) << 1] = 0;     seg[t][idx][(L & 1) << 1 | 1] = 0;    }    else if (L < R)    {     int M = L + R >> 1;     build(t, 2 * idx, L, M);     build(t, 2 * idx + 1, M + 1, R);     seg[t][idx] = merge(seg[t][2 * idx], seg[t][2 * idx + 1]);    }   }      void upd(int t, int idx, int L, int R, int l, int r, int v)   {    l = max(L, l); r = min(R, r); prop(t, idx, L, R);    if (l <= r)    {     if (L == l && R == r) {lz[t][idx] += v; prop(t, idx, L, R);}     else     {      int M = L + R >> 1;      upd(t, 2 * idx, L, M, l, r, v);      upd(t, 2 * idx + 1, M + 1, R, l, r, v);      seg[t][idx] = merge(seg[t][2 * idx], seg[t][2 * idx + 1]);     }    }   }      array<int, 4> qry(int t, int idx, int L, int R, int l, int r)   {    l = max(L, l); r = min(R, r);    if (l <= r)    {     prop(t, idx, L, R);     if (L == l && R == r) {return seg[t][idx];}     else     {      int M = L + R >> 1;      return merge(qry(t, 2 * idx, L, M, l, r), qry(t, 2 * idx + 1, M + 1, R, l, r));     }    }    return {INF, -INF, INF, -INF};   }      int main()   {    cin >> N;    for (int i = 1; i <= N; i++)    {     int x; cin >> x;     idx[x].push_back(i);    }    build(0, 1, 0, N);    build(1, 1, 0, N);    for (int i = 1; i <= N; i++)    {     upd(i & 1, 1, 0, N, i, N, -1);    }    for (int i = 1; i <= N; i++)    {     for (const auto &x : idx[i])     {      for (int j = 0; j < 2; j++)      {       array<int, 4> A = qry(j, 1, 0, N, 0, x - 1), B = qry(j, 1, 0, N, x, N);       ans[x] = max(ans[x], max(B[1], B[3]) - A[j << 1]);       ans[x] = max(ans[x], A[j << 1 | 1] - min(B[0], B[2]));        }      }     for (const auto &x : idx[i])      {      for (int j = 0; j < 2; j++) upd(j, 1, 0, N, x, N, 1);     }     for (const auto &x : idx[i])     {      for (int j = 0; j < 2; j++)      {       upd(j, 1, 0, N, x, N, -1);       array<int, 4> A = qry(j, 1, 0, N, 0, x - 1), B = qry(j, 1, 0, N, x, N);       ans[x] = max(ans[x], max(B[1], B[3]) - A[j << 1]);       ans[x] = max(ans[x], A[j << 1 | 1] - min(B[0], B[2]));       upd(j, 1, 0, N, x, N, 1);      }     }    }    for (int i = 1; i <= N; i++)    {     cout << ans[i] <<    n [i == N];    }    return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   map<pair<long long, long long>, long long> d;   long long solve(long long n, long long t) {     if (d.count(make_pair(n, t))) return d[make_pair(n, t)];     if (n == 0) return d[make_pair(n, t)] = 0;     long long l = 1, p = 0;     while (2 * l <= n) {       l *= 2;       p++;     }     if (t == 1) return d[make_pair(n, t)] = p + 1;     if (n <= 2) return d[make_pair(n, t)] = 0;     long long ans = solve(l / 2 - 1, t);     if (t % 2 == 0) ans += solve(l / 2 - 1, t / 2);     if (n != l && t % 2 == 0) ans += solve(n - l, t / 2);     return d[make_pair(n, t)] = ans;   }   int main() {     long long n, t;     cin >> n >> t;     long long ans = solve(n + 1, t);     if (t == 1) ans--;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 710;   const int MOD = 1000000007;   int n;   int mate[MAXN];   long long int dp[MAXN][MAXN][3][3];   char v[MAXN];   stack<int, vector<int> > s;   long long int solve(int l, int r, int bl, int br) {     long long int& ans = dp[l][r][bl][br];     if (ans != -1) return ans;     if (l > r) return ans = 1;     ans = 0;     int mateL = mate[l];     for (int colorL = 1; colorL <= 2; colorL++) {       if (colorL == bl) continue;       long long int left = solve(l + 1, mateL - 1, colorL, 0);       long long int right = solve(mateL + 1, r, 0, br);       ans += left * right;     }     for (int colorL = 1; colorL <= 2; colorL++) {       if (mateL == r && colorL == br) continue;       long long int left = solve(l + 1, mateL - 1, 0, colorL);       long long int right = solve(mateL + 1, r, colorL, br);       ans += left * right;     }     ans %= MOD;     return ans;   }   int main() {     scanf(  %s , v);     n = strlen(v);     for (int i = 0; i < n; i++) {       if (v[i] ==  ( )         s.push(i + 1);       else {         int p = s.top();         s.pop();         mate[p] = i + 1;         mate[i + 1] = p;       }     }     memset(dp, -1, sizeof(dp));     printf( %lld n , solve(1, n, 0, 0));   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, cnt, c[100100], d[100100];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   vector<pair<int, pair<int, int> > > graph[100100];   vector<pair<int, pair<int, int> > > edge, v;   bool mark[100100];   pair<int, int> p[100100];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) d[i] = 1e9;     for (int i = 0; i < m; i++) {       cin >> x >> y >> z;       graph[x].push_back(make_pair(y, make_pair(z, i)));       graph[y].push_back(make_pair(x, make_pair(z, i)));       edge.push_back(make_pair(z, make_pair(x, y)));       if (z) cnt++;     }     d[1] = 0;     pq.push(make_pair(0, 1));     while (!pq.empty()) {       x = pq.top().second;       pq.pop();       for (int i = 0; i < graph[x].size(); i++) {         y = graph[x][i].first;         if (d[x] + 1 <= d[y]) {           if (d[x] + 1 < d[y]) p[y] = make_pair(x, graph[x][i].second.second);           d[y] = d[x] + 1;           if (c[x] + graph[x][i].second.first > c[y]) {             p[y] = make_pair(x, graph[x][i].second.second);             c[y] = c[x] + graph[x][i].second.first;           }           pq.push(make_pair(d[y], y));         }       }     }     x = n;     while (x != 1) {       y = x;       x = p[y].first;       if (edge[p[y].second].first == 0) v.push_back(edge[p[y].second]);       mark[p[y].second] = 1;     }     for (int i = 0; i < edge.size(); i++) {       if (!mark[i] && edge[i].first) v.push_back(edge[i]);     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i].second.first <<     << v[i].second.second <<                << (!v[i].first) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d, ans = 128, x[128], sum[128];   int main() {     cin >> n >> d;     for (int i = 0; i < n; ++i) cin >> x[i];     sort(x, x + n);     for (int l = 0; l < n; ++l)       for (int r = l; r < n; ++r)         if (x[r] - x[l] <= d) ans = min(ans, l + n - 1 - r);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1e9 + 7, oo = 1e9;   const ll loo = 1e18;   ll modpow(ll a, ll b) {     ll ans = 1;     for (; b; b /= 2, a = a * a % mod)       if (b & 1) ans = (ans * a) % mod;     return ans;   }   ll gcd(ll a, ll b) {     while (a) b %= a, swap(a, b);     return b;   }   const bool DEBUG = 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int n = s.length();     int pre[n][3];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) pre[i][j] = i ? pre[i - 1][j] : -oo;       pre[i][s[i] -  a ] = i;     }     stringstream ss;     int i = 0, j = n - 1;     int cnt = 0;     while (i <= j) {       int jj = pre[j][s[i] -  a ];       if (jj - i >= 0 && (jj - i - 1) / 2 + cnt + (1 + (i != jj)) >= n / 2) {         j = jj - 1;         cnt += 1 + (i != jj);         ss << s[i];       }       i++;     }     string t = ss.str();     string r;     if (cnt & 1)       r = t.substr(0, t.length() - 1);     else       r = s.substr(0, t.length());     reverse(r.begin(), r.end());     cout << t << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   int n, a, b, da, db;   vector<int> nei[N + 1];   int dep[N + 1], dp[N + 1];   int ans;   void dfs(int x = a, int fa = 0) {     vector<int> v;     v.push_back(dep[x]);     dp[x] = dep[x];     for (int i = 0; i < nei[x].size(); i++) {       int y = nei[x][i];       if (y == fa) continue;       dep[y] = dep[x] + 1;       dfs(y, x);       v.push_back(dp[y]);       dp[x] = max(dp[x], dp[y]);     }     sort(v.begin(), v.end(), greater<int>());     if (v.size() >= 2) ans = max(ans, v[0] + v[1] - 2 * dep[x]);   }   void mian() {     scanf( %d%d%d%d%d , &n, &a, &b, &da, &db);     for (int i = 1; i <= n; i++) nei[i].clear();     for (int i = 1; i <= n; i++) dep[i] = dp[i] = 0;     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       nei[x].push_back(y);       nei[y].push_back(x);     }     if (db < 2 * da + 1) return puts( Alice ), void();     ans = 0;     dfs();     if (ans >= 2 * da + 1 && dep[b] > da)       puts( Bob );     else       puts( Alice );   }   int main() {     int testnum;     cin >> testnum;     while (testnum--) mian();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long power(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) {         ret = ret * a % mod;       }       a = a * a % mod;       n >>= 1;     }     return ret;   }   vector<long long> st;   long long C(long long n, long long k) {     long long ret = st[n];     ret = ret * power(st[k], mod - 2) % mod;     ret = ret * power(st[n - k], mod - 2) % mod;     return ret;   }   long long solve(long long n, long long k) {     if (k >= n) return 0;     st.resize(n + 1, 1);     for (long long i = 1; i <= n; i++) st[i] = st[i - 1] * i % mod;     long long ret = 0, c = n - k;     for (long long i = 0; i <= c; i++) {       if ((i & 1) == (c & 1))         ret = (ret + mod + (C(c, i) * power(i, n))) % mod;       else         ret = (ret + mod - (C(c, i) * power(i, n))) % mod;     }     ret = ret * C(n, c) % mod;     return k > 0 ? ret * 2 % mod : ret;   }   int32_t main() {     long long n, k;     cin >> n >> k;     cout << solve(n, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long MAX = 8e18;   const long long MIN = -8e18;   int n;   long long x[N];   long long y[N];   long long z[N];   vector<long long> ansX;   vector<long long> ansY;   vector<long long> ansZ;   inline long long llabs(const long long &a, const long long &b) {     long long res = a - b;     return (res >= 0 ? res : -res);   }   inline long long calDist(long long z0, pair<long long, long long> &xy) {     long long minA, maxA, minB, maxB, h, dist2, a, b;     int i, j, k;     minA = minB = MAX;     maxA = maxB = MIN;     for (i = 0; i < n; i++) {       h = llabs(z0, z[i]);       minA = min(minA, x[i] + y[i] - h);       maxA = max(maxA, x[i] + y[i] + h);       minB = min(minB, x[i] - y[i] - h);       maxB = max(maxB, x[i] - y[i] + h);     }     dist2 = max(maxA - minA, maxB - minB);     a = (maxA + minA) / 2;     b = (maxB + minB) / 2;     xy.first = (a + b) / 2;     xy.second = (a - b) / 2;     return dist2;   }   inline void solve() {     int i;     long long bestZ, bestY, bestX, bestDist, curDist, curY, curX, initX, initY,         curZ, d;     bestDist = MAX;     pair<long long, long long> xy;     bestZ = 0;     bestDist = calDist(bestZ, xy);     d = 1e18;     while (d >= 1) {       curZ = bestZ + d;       curDist = calDist(curZ, xy);       if (curDist < bestDist) {         bestZ = curZ;         bestDist = curDist;         continue;       }       curZ = bestZ - d;       curDist = calDist(curZ, xy);       if (curDist < bestDist) {         bestZ = curZ;         bestDist = curDist;         continue;       }       d /= 2;     }     calDist(bestZ, xy);     initX = xy.first;     initY = xy.second;     bestDist = MAX;     for (curX = initX - 1; curX <= initX + 1; curX++) {       for (curY = initY - 1; curY <= initY + 1; curY++) {         curDist = 0;         for (i = 0; i < n; i++) {           curDist = max(curDist, llabs(x[i] - curX) + llabs(y[i] - curY) +                                      llabs(bestZ - z[i]));         }         if (curDist < bestDist) {           bestDist = curDist;           bestX = curX;           bestY = curY;         }       }     }     ansX.push_back(bestX);     ansY.push_back(bestY);     ansZ.push_back(bestZ);   }   int main() {     int t, i, k;     scanf( %d , &t);     for (k = 0; k < t; k++) {       scanf( %d , &n);       for (i = 0; i < n; i++) {         scanf(              %l               ld               %l               ld               %l               ld ,             &x[i], &y[i], &z[i]);       }       solve();     }     for (i = 0; i < t; i++) {       printf(            %l             ld                           %l             ld                           %l             ld              n ,           ansX[i], ansY[i], ansZ[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1e16;   const long long ninf = LLONG_MIN;   const double eps = 1e-12;   const long long N = 1000005;   const double PI = 3.14159265358979323846;   const long long LOGN = 19;   long long n, m;   long long s[N], t[N];   char a[N];   long long dp[(1 << 21)];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     cin >> m;     sort(s, s + n);     reverse(s, s + n);     for (int i = 0; i < m; i++) cin >> a[i] >> t[i];     for (long long mask = (1 << m) - 1; mask >= 0; mask--) {       long long done = __builtin_popcount(mask);       if (done == m) {         dp[mask] = 0;         continue;       }       if (a[done] ==  p ) {         for (int j = 0; j < m; j++) {           if ((mask & (1 << j)) == 0) {             dp[mask] = (t[done] == 1 ? s[j] : -s[j]) + dp[mask | (1 << j)];             break;           }         }       } else {         if (t[done] == 1) {           dp[mask] = -inf;           for (int j = 0; j < m; j++) {             dp[mask] = max(dp[mask], dp[mask | (1 << j)]);           }         } else {           dp[mask] = inf;           for (int j = 0; j < m; j++) {             dp[mask] = min(dp[mask], dp[mask | (1 << j)]);           }         }       }     }     cout << dp[0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5, M = 350;   long long dp[5][N], B, a[N], b[N], t[N], n, m, d, minans = 1e9 + 10, dpL[N],                                                     dpR[N];   int last, ldel;   deque<int> stac;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> t[i];       B += b[i];     }     for (int j = 0; j < n; j++) dp[0][j] = abs(a[0] - (j + 1));     for (int i = 1; i < m; i++) {       last = (i - 1) % 2;       for (int j = 0; j < n; j++) {         ldel = j;         while (!stac.empty() && stac.front() < (j - ((t[i] - t[i - 1]) * d)))           stac.pop_front();         while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])           ldel = stac.back(), stac.pop_back();         if (stac.empty())           dpL[j] = dp[last][ldel];         else           dpL[j] = dp[last][stac.front()];         stac.push_back(j);       }       for (int j = n - 1; j >= 0; j--) {         ldel = j;         while (!stac.empty() && stac.front() > (j + ((t[i] - t[i - 1]) * d)))           stac.pop_front();         while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])           ldel = stac.back(), stac.pop_back();         if (stac.empty())           dpR[j] = dp[last][ldel];         else           dpR[j] = dp[last][stac.front()];         stac.push_back(j);       }       for (int j = 0; j < n; j++)         dp[i % 2][j] =             min(min(dpR[j], dpL[j]), dp[last][j]) + abs(a[i] - (j + 1));       stac.clear();     }     for (int i = 0; i < n; i++) minans = min(minans, dp[(m - 1) % 2][i]);     cout << B - minans;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long st, en;     node() {}     node(long long _st, long long _en) : st(_st), en(_en) {}   };   int main() {     int n, b, t, d;     long long etime[200000];     long long ftime;     int qlen = 0;     cin >> n >> b;     cin >> t >> d;     etime[0] = t + d;     ftime = 1ll * t + d;     int len = 0;     queue<node> ws;     node temp;     cout << etime[0] <<    ;     for (int i = 1; i < n; i++) {       cin >> t >> d;       while (!ws.empty()) {         temp = ws.front();         if (t >= temp.st) {           ws.pop();           len--;         } else           break;       }       if (t < ftime) {         if (len < b) {           ws.push(node(ftime, ftime + d));           len++;           etime[i] = ftime + d;           ftime += d;         } else {           etime[i] = -1;         }       } else {         etime[i] = 1ll * t + d;         ftime = 1ll * t + d;       }       cout << etime[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, pair<long long, long long> > Mp;   pair<long long, long long> DFS(pair<long long, long long> u) {     if (u.second < 10)       return pair<long long, long long>(u.first || u.second,                                         u.second - max(u.second, u.first));     if (Mp[u].first) return Mp[u];     long long ans = 0, p = 1;     while (p <= u.second / 10) p *= 10;     pair<long long, long long> res =         DFS(pair<long long, long long>(max(u.first, u.second / p), u.second % p));     ans += res.first;     res = DFS(pair<long long, long long>(u.first, u.second / p * p + res.second));     return Mp[u] = pair<long long, long long>(res.first + ans, res.second);   }   int main() {     long long n;     scanf( %lld , &n);     printf( %lld n , DFS(pair<long long, long long>(0, n)));   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const int LOG = 18;   int n, m, par[MAX][LOG], h[MAX];   vector<int> graph[MAX];   int par_tree[MAX], mini[MAX];   void lca_dfs(int node, int p) {     if (p + 1) h[node] = h[p] + 1;     par[node][0] = p;     for (int k = 1; k < LOG; k++)       if (par[node][k - 1] + 1) par[node][k] = par[par[node][k - 1]][k - 1];     for (auto& target : (graph[node])) {       if (target != p) lca_dfs(target, node);     }   }   int get_lca(int a, int b) {     if (h[b] > h[a]) swap(a, b);     for (int k = LOG - 1; k >= 0; k--) {       if (par[a][k] + 1 && h[par[a][k]] >= h[b]) a = par[a][k];     }     if (a == b) return a;     for (int k = LOG - 1; k >= 0; k--)       if (par[a][k] != par[b][k]) {         a = par[a][k];         b = par[b][k];       }     return par[a][0];   }   int dist(int a, int b) { return h[a] + h[b] - 2 * h[get_lca(a, b)]; }   int processed[MAX], sizes[MAX];   int get_sizes(int node, int p) {     sizes[node] = 1;     for (auto& target : (graph[node])) {       if (!processed[target] && target != p)         sizes[node] += get_sizes(target, node);     }     return sizes[node];   }   int cent, cent_cost;   void select_cent(int node, int p, int current) {     int node_max = sizes[current] - sizes[node];     for (auto& target : (graph[node])) {       if (!processed[target] && target != p) {         node_max = max(node_max, sizes[target]);         select_cent(target, node, current);       }     }     if (node_max < cent_cost) {       cent = node;       cent_cost = node_max;     }   }   int process(int current) {     get_sizes(current, -1);     if (sizes[current] <= 1) return current;     cent = current;     cent_cost = ((int)1e9 + 10);     select_cent(current, -1, current);     int centroid = cent;     processed[centroid] = 1;     for (auto& target : (graph[centroid])) {       if (!processed[target]) {         int next_cent = process(target);         par_tree[next_cent] = centroid;       }     }     return centroid;   }   void update(int node) {     int cur = node;     while (cur > 0) {       mini[cur] = min(mini[cur], dist(cur, node));       cur = par_tree[cur];     }   }   int query(int node) {     int cur = node, ans = ((int)1e9 + 10);     while (cur > 0) {       ans = min(ans, mini[cur] + dist(node, cur));       cur = par_tree[cur];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int(i) = (0); (i) < (MAX); (i)++) mini[i] = ((int)1e9 + 10);     memset(par, -1, sizeof(par));     cin >> n >> m;     int a, b;     for (int(i) = (0); (i) < (n - 1); (i)++) {       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     lca_dfs(1, -1);     int root = process(1);     par_tree[root] = -1;     int type, node;     update(1);     for (int(k) = (0); (k) < (m); (k)++) {       cin >> type >> node;       if (type == 1) {         update(node);       } else {         cout << (query(node)) <<   n ;         ;       }     }   }