malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int st[maxn << 2];   int a[maxn], b[maxn];   vector<int> pos[maxn];   void build(int id, int l, int r) {     if (l == r) {       st[id] = a[l];       return;     }     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);     st[id] = min(st[id << 1], st[id << 1 | 1]);   }   void update(int id, int l, int r, int u, int val) {     if (l > u || r < u) return;     if (l == r) {       st[id] = val;       return;     }     int mid = (l + r) >> 1;     update(id << 1, l, mid, u, val);     update(id << 1 | 1, mid + 1, r, u, val);     st[id] = min(st[id << 1], st[id << 1 | 1]);   }   int GetMin(int id, int l, int r, int u, int v) {     if (l > v || r < u) return 1e9;     if (u <= l && r <= v) return st[id];     int mid = (l + r) >> 1;     return min(GetMin(id << 1, l, mid, u, v),                GetMin(id << 1 | 1, mid + 1, r, u, v));   }   string Solve() {     int n;     cin >> n;     for (int i = (1), _b = (n); i <= _b; ++i) pos[i].clear();     for (int i = (1), _b = (n); i <= _b; ++i) cin >> a[i];     for (int i = (n), _b = (1); i >= _b; --i) pos[a[i]].push_back(i);     for (int i = (1), _b = (n); i <= _b; ++i) cin >> b[i];     build(1, 1, n);     int l = 1;     for (int i = (1), _b = (n); i <= _b; ++i) {       if (pos[b[i]].empty()) return  NO ;       int nxt = pos[b[i]].back();       pos[b[i]].pop_back();       if (GetMin(1, 1, n, l, nxt) != b[i]) return  NO ;       update(1, 1, n, nxt, 1e9);     }     return  YES ;   }   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q;     for (int i = (1), _b = (q); i <= _b; ++i) cout << Solve() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q;     cin >> q;     while (q--) {       long long int n;       cin >> n;       long long int x, y;       int l, u, r, s;       long long int nl = -100000, nu = 100000, nr = 100000, ns = -100000;       for (long long int i = 0; i < n; i++) {         cin >> x >> y >> l >> u >> r >> s;         if (l == 0 && nl <= x) {           nl = x;         }         if (u == 0 && nu >= y) {           nu = y;         }         if (r == 0 && nr >= x) {           nr = x;         }         if (s == 0 && ns <= y) {           ns = y;         }       }       if (ns <= nu && nl <= nr) {         std::cout << 1 <<     << nl <<     << ns << std::endl;       } else {         std::cout << 0 << std::endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long A = 31, mod = 1000000033LL;   vector<string> read(int n) {     vector<string> ans(n);     for (auto &x : ans) cin >> x;     return ans;   }   vector<long long> hsh(vector<string> vec, long long a) {     vector<long long> ans;     for (auto x : vec) {       long long h = 0;       for (auto y : x) h = (h * a + (y -  a )) % mod;       ans.push_back(h);     }     return ans;   }   long long hsh(vector<long long> &vec, int beg, int end, long long a) {     long long h = 0;     for (int i = beg; i < end; i++) h = (h * a + vec[i]) % mod;     return h;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     long long Am = 1;     for (int i = 0; i < m; i++) Am = Am * A % mod;     auto m1 = read(n), tmp2 = read(m);     vector<string> m2(n, string(m,    ));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) m2[i][j] = tmp2[j][i];     auto h1 = hsh(m1, A), h2 = hsh(m2, Am);     vector<pair<long long, int>> vec;     for (int i = 0; i + m <= n; i++) vec.emplace_back(hsh(h1, i, i + m, Am), i);     sort(vec.begin(), vec.end());     for (int i = 0; i + m <= n; i++) {       auto h = hsh(h2, i, i + m, A);       auto p = lower_bound(vec.begin(), vec.end(), make_pair(h, 0));       if (p != vec.end() && p->first == h) {         cout << p->second + 1 <<     << i + 1 << endl;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, const string& delim =    ) {     vector<string> res;     string t;     for (int i = 0; i != s.size(); i++) {       if (delim.find(s[i]) != string::npos) {         if (!t.empty()) {           res.push_back(t);           t =   ;         }       } else {         t += s[i];       }     }     if (!t.empty()) {       res.push_back(t);     }     return res;   }   vector<int> splitInt(const string& s, const string& delim =    ) {     vector<string> tok = split(s, delim);     vector<int> res;     for (int i = 0; i != tok.size(); i++) res.push_back(atoi(tok[i].c_str()));     return res;   }   template <typename T>   void print(T a) {     cerr << a;   }   static void print(long long a) { cerr << a <<  L ; }   static void print(string a) { cerr <<     << a <<    ; }   template <typename T>   void print(vector<T> a) {     cerr <<  { ;     for (int i = 0; i != a.size(); i++) {       if (i != 0) cerr <<  ,  ;       print(a[i]);     }     cerr <<  }  << endl;   }   char flag[1000005];   int main() {     string s;     while (cin >> s) {       memset(flag, 0, sizeof(flag));       reverse(s.begin(), s.end());       for (int i = 0, _n = (s.size()); i < _n; i++) flag[i] = s[i] -  0 ;       int i = 0, n = s.size();       while (i < n) {         int count = 0;         while (i < n && flag[i + count] == 1) count++;         if (count > 1) {           for (int j = (i), _n = (i + count - 1); j <= _n; j++) flag[j] = 0;           flag[i] = -1;           flag[i + count] = 1;           i = i + count - 1;         }         i++;       }       int count = 0;       for (int i = 0, _n = (n + 3); i < _n; i++) count += (flag[i] != 0);       printf( %d n , count);       for (int i = (0), _n = (n + 3); i <= _n; i++)         if (flag[i] != 0) {           if (flag[i] < 0)             printf( - );           else             printf( + );           printf( 2^%d n , i);         }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000 )   bool ascending(int i, int j) { return (i < j); }   bool descending(int i, int j) { return (i > j); }   using namespace std;   const int MOD = 1000 * 1000 * 1000 + 7;   unsigned long long powmod(unsigned long long a, unsigned long long b,                             unsigned long long m) {     unsigned long long x = a, p = 1;     while (b > 0) {       if (b % 2) p = ((p % m) * (x % m)) % m;       b /= 2;       x = ((x % m) * (x % m)) % m;     }     return p;   }   int main() {     int mersenne[] = {0,       2,       3,       5,        7,       13,                       17,      19,      31,      61,       89,      107,                       127,     521,     607,     1279,     2203,    2281,                       3217,    4253,    4423,    9689,     9941,    11213,                       19937,   21701,   23209,   44497,    86243,   110503,                       132049,  216091,  756839,  859433,   1257787, 1398269,                       2976221, 3021377, 6972593, 13466917, 20996011};     int n;     cin >> n;     cout << powmod(2, mersenne[n] - 1, MOD) - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     long long val, pos;   };   deque<long long> dq;   bool flag = false;   void go(long long a, long long b) {     if (a > b) return;     if (a == b) {       cout <<  YES  << endl;       dq.push_back(b);       cout << dq.size() << endl;       flag = true;       auto it = dq.begin();       while (it != dq.end()) {         cout << *it <<    ;         it++;       }       cout << endl;     }     dq.push_back(a);     go(a * 2, b);     go(a * 10 + 1, b);     dq.pop_back();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b;     cin >> a >> b;     go(a, b);     if (flag == false) cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   const long double EPSILON = 0.000000001;   const long long int mod = 1000000007;   const long long int AM = 2e5 + 5;   const long double pi = 3.14159265358979323846;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   using namespace std;   long long int fact(long long int n) {     long long int ans = 1;     for (long long int i = 1; i <= n; i++) ans *= i;     return ans;   }   long long int powm(long long int a, long long int b, long long int n) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % n;       }       y = (y * y) % n;       b /= 2;     }     return x % n;   }   long long int pow(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   long long int min(long long int a, long long int b) {     if (a > b)       return b;     else       return a;   }   bool cmp(long double x, long double y) {     if (abs(x - y) <= EPSILON) return 1;     return 0;   }   long long int nCrModp(long long int n, long long int r, long long int p) {     if (r > n - r) r = n - r;     long long int C[r + 1];     memset(C, 0, sizeof(C));     C[0] = 1;     for (long long int i = 1; i <= n; i++) {       for (long long int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;     }     return C[r];   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int NcR(long long int n, long long int r) {     long long p = 1, k = 1;     if (n - r < r) r = n - r;     if (r != 0) {       while (r) {         p *= n;         k *= r;         long long m = gcd(p, k);         p /= m;         p %= mod;         k /= m;         n--;         r--;       }     } else       p = 1;     return p;   }   int main() {     long long int n;     cin >> n;     vector<long long int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort((v).begin(), (v).end());     long long int cnt = 0;     long long int sum = 0;     for (int i = 0; i < n; i++) {       if (sum <= v[i]) cnt++;       if (sum <= v[i]) sum += v[i];     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   struct zt {     int ss, ii;   } frm[1 << 22], ans[25];   struct node {     int l, r, t, id;   } a[25], b[25];   bool cmp1(node aa, node bb) { return aa.l < bb.l; }   bool cmp2(node aa, node bb) { return aa.t < bb.t; }   int N, P, S, f[1 << 22];   void dfs(int s, int ii) {     if (!s) return;     ans[frm[s].ii] = (zt){frm[s].ss, ii};     dfs(s ^ (1 << (frm[s].ii - 1)), ii);   }   void SLV1() {     if (f[S] == inf) {       puts( NO );       exit(0);     }     puts( YES );     dfs(S, 1);     for (int i = 1; i <= N; i++) {       printf( %d %d n , ans[i].ii, ans[i].ss);     }   }   void SLV2() {     int s1 = 0;     int s2 = -233;     for (; s1 <= S; s1++) {       if (f[s1] < inf && f[S ^ s1] < inf) {         s2 = (S ^ s1);         break;       }     }     if (s2 == -233) {       puts( NO );       exit(0);     }     puts( YES );     dfs(s1, 1);     dfs(s2, 2);     for (int i = 1; i <= N; i++) {       printf( %d %d n , ans[i].ii, ans[i].ss);     }   }   int main() {     scanf( %d%d , &N, &P);     for (int i = 1; i <= N; i++) {       scanf( %d%d%d , &a[i].l, &a[i].r, &a[i].t);       a[i].id = i;       a[i].r += a[i].l - 1;       b[i] = a[i];     }     sort(a + 1, a + 1 + N, cmp1);     sort(b + 1, b + 1 + N, cmp2);     S = (1 << N) - 1;     memset(f, 0x3f, sizeof f);     f[0] = 1;     for (int s = 0; s < S; s++) {       if (f[s] != inf) {         int tim = f[s];         int pit = 1;         for (int i = 1; i <= N; i++) {           if ((s >> (b[i].id - 1)) & 1) continue;           for (; pit <= N && tim + b[i].t >= a[pit].l; pit++) {             if (tim >= a[pit].l || ((s >> (a[pit].id - 1)) & 1))               tim = max(tim, a[pit].r + 1);           }           if (tim + b[i].t < b[i].l) {             if (f[s | (1 << (b[i].id - 1))] > tim + b[i].t) {               f[s | (1 << (b[i].id - 1))] = tim + b[i].t;               frm[s | (1 << (b[i].id - 1))] = (zt){tim, b[i].id};             }           }         }       }     }     if (P == 1)       SLV1();     else       SLV2();   }
#include <bits/stdc++.h>   using namespace std;   int b[1111][1111], n, m, k, q1, q2, xs, ys, step = 0, x, y, c;   vector<char> v;   char a[1111][1111];   queue<pair<int, int> > q;   void add(int x, int y, int c) {     if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] ==  *  || b[x][y] <= c)       return;     b[x][y] = c;     q.push(make_pair(x, y));   }   bool check(int x, int y) {     if (step + b[x][y] > k) return false;     if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] ==  * ) return false;     return true;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  X ) {           xs = i;           ys = j;         }       }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) b[i][j] = 1e9;     b[xs][ys] = 0;     q.push(make_pair(xs, ys));     while (!q.empty()) {       x = q.front().first;       y = q.front().second;       q.pop();       c = b[x][y] + 1;       add(x + 1, y, c);       add(x - 1, y, c);       add(x, y + 1, c);       add(x, y - 1, c);     }     int x = xs;     int y = ys;     while (81 == 81) {       if (v.size() == k && x == xs && y == ys) break;       step = v.size();       if (check(x + 1, y)) {         v.push_back( D );         x++;         continue;       }       if (check(x, y - 1)) {         v.push_back( L );         y--;         continue;       }       if (check(x, y + 1)) {         v.push_back( R );         y++;         continue;       }       if (check(x - 1, y)) {         v.push_back( U );         x--;         continue;       }       cout <<  IMPOSSIBLE ;       return 0;     }     for (int i = 0; i < v.size(); i++) cout << v[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, in;   long long shift(long long i) { return (1 << i); }   void getx(long long x, long long y) {     cout <<  ?   << x <<     << y << endl;     cin >> in;     return;   }   int main() {     ios_base::sync_with_stdio(false);     long long curbit = 29;     getx(0, 0);     long long start = in;     while (curbit >= 0) {       if (start == 0) {         getx(a ^ shift(curbit), b);         if (in == -1) {           a |= shift(curbit);           b |= shift(curbit);           getx(a, b);           start = in;         }         curbit--;         continue;       }       getx(a ^ shift(curbit), b ^ shift(curbit));       while (in == start) {         if (start == 1) {           getx(a ^ shift(curbit), b);           if (in == -1) {             a |= shift(curbit);             b |= shift(curbit);           }         } else {           getx(a, b ^ shift(curbit));           if (in == 1) {             a |= shift(curbit);             b |= shift(curbit);           }         }         if (curbit == 0) break;         curbit--;         getx(a ^ shift(curbit), b ^ shift(curbit));       }       if (in != start) {         if (start == 1)           a |= shift(curbit);         else if (start == 0) {           a |= shift(curbit);           b |= shift(curbit);         } else           b |= shift(curbit);         getx(a, b);         start = in;       }       curbit--;     }     cout <<  !   << a <<     << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char arr[1002][7];   bool sit = false;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , arr[i]);       if (!sit) {         if (arr[i][0] ==  O  && arr[i][1] ==  O ) {           sit = true;           arr[i][0] = arr[i][1] =  + ;         } else if (arr[i][3] ==  O  && arr[i][4] ==  O ) {           sit = true;           arr[i][3] = arr[i][4] =  + ;         }       }     }     if (sit) {       printf( YES n );       for (int i = 0; i < n; i++) printf( %s n , arr[i]);     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y;   int main() {     cin >> x >> y >> m;     if (x >= m || y >= m) {       cout << 0 << endl;       return 0;     }     if ((x <= 0 && y <= 0)) {       cout <<  -1  << endl;       return 0;     }     long long ans = 0;     while (x < m && y < m) {       if (x < 0) {         ans += ((-x) / y);         x = x + ((-x) / y) * y;       } else if (y < 0) {         ans += ((-y) / x);         y = y + ((-y) / x) * x;       }       ans++;       if (x < y)         x = x + y;       else         y = y + x;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int md = 1000000007;   const int maxn = 30303;   const int maxk = 220;   const int maxn4 = 4 * maxn;   const long long inf = 2020202020202020202LL;   int n, k, a[maxn];   int ans[maxn][maxk], ansp[maxn][maxk], ansm[maxn][maxk], t1, t2, t3, t4, t5, t6;   int main() {     ios::ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i + 1];     int mx = -md, mn = -md;     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxk; j++) {         ansp[i][j] = -md;         ansm[i][j] = -md;         ans[i][j] = -md;       }     for (int i = 1; i <= n; i++) {       mx = max(mx + a[i], a[i]);       ansp[i][1] = mx;       mn = max(mn - a[i], -a[i]);       ansm[i][1] = mn;     }     for (int w = 2; w <= k; w++) {       t1 = ansp[w - 1][w - 1];       t2 = ansm[w - 1][w - 1];       t3 = ansm[w - 1][w - 1];       t4 = ansp[w - 1][w - 1];       t5 = ansm[w - 1][w - 1];       t6 = ansp[w - 1][w - 1];       for (int i = w; i <= n; i++) {         ans[i][w] = max(t5 + a[i], t6 - a[i]);         ansp[i][w] = max(t1, t3 + 2 * a[i]);         ansm[i][w] = max(t2, t4 - 2 * a[i]);         t1 = max(t1, ansp[i][w - 1]);         t2 = max(t2, ansm[i][w - 1]);         t3 = max(t3 + 2 * a[i], ansm[i][w - 1]);         t4 = max(t4 - 2 * a[i], ansp[i][w - 1]);         t5 = max(t5 + a[i], ansm[i][w - 1]);         t6 = max(t6 - a[i], ansp[i][w - 1]);       }     }     int an = -md;     for (int i = 1; i <= n; i++) an = max(an, ans[i][k]);     cout << an;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const long long inf = 1e18;   int f[maxn][32], rt;   long long ans, a[maxn];   vector<int> G[maxn];   void dfs(int u, int p) {     long long d = 0;     f[u][0] = p;     for (d = 1; d <= 20; d++) {       if (f[u][d - 1] != -1) f[u][d] = f[f[u][d - 1]][d - 1];     }     long long tmp = inf;     for (d = 0; d <= 20; d++) {       if (f[u][d] != -1)         tmp = min(tmp, (d + 1) * a[f[u][d]] + a[u]);       else         break;     }     tmp = min(tmp, (d + 1) * a[rt] + a[u]);     if (p != -1) ans += tmp;     for (int v : G[u])       if (v != p) dfs(v, u);   }   int main() {     ios::sync_with_stdio(false);     memset(f, -1, sizeof(f));     int n;     cin >> n;     a[rt] = inf;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < a[rt]) rt = i;     }     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(rt, -1);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 2e18;   const int N = 1231234;   int n, m;   int a[N], b[N];   bool ok(long long x) {     int i, j;     for (i = 0, j = 0; i < m; ++i) {       while (j < n && abs(b[i] - a[j]) <= x) j++;     }     return j == n;   }   int main() {     while (cin >> n >> m) {       int i, j;       for (i = 0; i < n; ++i) scanf( %d , &a[i]);       for (i = 0; i < m; ++i) scanf( %d , &b[i]);       long long l = 0, r = INF;       while (l <= r) {         long long mid = (l + r) >> 1;         if (ok(mid))           r = mid - 1;         else           l = mid + 1;       }       printf( %I64d n , l);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[3][55], b[55];   int sum(int row, int f, int e) {     int res = 0;     for (int i = f; i <= e; ++i) res += a[row][i];     return res;   }   int main() {     cin >> n;     for (int x = 1; x <= 2; ++x)       for (int i = 1; i < n; ++i) cin >> a[x][i];     for (int i = 1; i <= n; ++i) cin >> b[i];     int ans = (1 << 30);     for (int i = 1; i < n; ++i)       for (int j = i + 1; j <= n; ++j)         ans = min(ans, sum(1, 1, i - 1) + sum(2, i, n - 1) + b[i] +                            sum(1, 1, j - 1) + sum(2, j, n - 1) + b[j]);     cout << ans;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, m;   string s[100000];   int a[100000];   int b[100000];   string name;   int id;   vector<pair<int, string> > All;   bool canMaxi(int k) {     pair<int, string> He = make_pair(-a[id], name);     He.first -= b[n - 1];     for (int i = k - 1; i >= 0; i--) {       pair<int, string> I = All[i];       I.first -= b[k - 1 - i];       if (He < I) return false;     }     return true;   }   int findMaxi() {     int l = n - 1, r = n - 1;     for (int i = 0; i < (int)((All).size()); i++)       if (make_pair(-a[id], name) < All[i]) {         l = i;         break;       }     while (r - l > 1) {       int k = (l + r) / 2;       if (canMaxi(k))         l = k;       else         r = k - 1;     }     if (l != r && canMaxi(r)) l++;     return l;   }   bool canMini(int k) {     pair<int, string> He = make_pair(-a[id], name);     He.first -= b[0];     for (int i = k; i < n - 1; i++) {       pair<int, string> I = All[i];       I.first -= b[(n - 1) - (i - k)];       if (!(He < I)) return false;     }     return true;   }   int findMini() {     int l = 0, r = n - 1;     for (int i = (int)((All).size()) - 1; i >= 0; i--)       if (make_pair(-a[id], name) < All[i]) {         r = i;         break;       }     while (r - l > 1) {       int k = (l + r) / 2;       if (canMini(k))         r = k;       else         l = k + 1;     }     if (l != r && canMini(l)) r--;     return r;   }   void solution() {     scanf( %d n , &n);     for (int i = 0, _n = (n); i < _n; ++i) {       char t[64];       scanf( %s %d n , t, a + i);       s[i] = string(t);     }     scanf( %d , &m);     for (int i = 0, _n = (m); i < _n; ++i) scanf( %d n , b + i);     sort(b, b + n, greater<int>());     cin >> name;     for (int i = 0, _n = (n); i < _n; ++i)       if (s[i] == name) {         id = i;         break;       }     for (int i = 0, _n = (n); i < _n; ++i)       if (i != id) All.push_back(make_pair(-a[i], s[i]));     sort((All).begin(), (All).end());     int mini = findMini();     int maxi = findMaxi();     printf( %d %d n , mini + 1, maxi + 1);   }   int main() {     solution();     return 0;   }
#include <bits/stdc++.h>   const int inf = 2000000000;   using namespace std;   vector<vector<int> > g;   vector<int> color;   vector<bool> on_cycle;   vector<int> parent;   int n;   bool isexit = false;   void dfs(int v, int p = -1) {     if (isexit) return;     color[v] = 1;     parent[v] = p;     for (int i = 0; i < (int)g[v].size(); i++) {       if (isexit) break;       if (color[g[v][i]] == 0)         dfs(g[v][i], v);       else if (color[g[v][i]] == 1 && g[v][i] != parent[v]) {         int j = v;         while (j != g[v][i]) {           on_cycle[j] = true;           j = parent[j];         }         on_cycle[g[v][i]] = true;         isexit = true;       }     }     color[v] = 3;   }   void dfs2(int v) {     for (int i = 0; i < (int)g[v].size(); i++)       if (color[g[v][i]] > color[v] + 1) {         color[g[v][i]] = color[v] + 1;         dfs2(g[v][i]);       }   }   int main() {     scanf( %d , &n);     g.resize(n + 1);     color.resize(n + 1);     on_cycle.resize(n + 1, false);     parent.resize(n + 1);     for (int i = 1; i <= n; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (color[i] == 0) dfs(i);     for (int i = 1; i <= n; i++)       if (on_cycle[i])         color[i] = 0;       else         color[i] = inf;     for (int i = 1; i <= n; i++)       if (on_cycle[i]) dfs2(i);     for (int i = 1; i <= n; i++) printf( %d  , color[i]);     return 0;   }