malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 15;   const int inf = 1e9;   const int md = 1e9 + 7;   const int shift = 1 << 17;   int n, m;   vector<vector<int> > g;   set<pair<int, int> > br;   int timer;   int tin[maxn], fup[maxn];   int used[maxn];   void dfs(int v, int p = -1) {     used[v] = 1;     tin[v] = fup[v] = timer++;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) continue;       if (used[to])         fup[v] = min(fup[v], tin[to]);       else {         dfs(to, v);         fup[v] = min(fup[v], fup[to]);         if (fup[to] > tin[v]) {           br.insert(make_pair(to, v));           br.insert(make_pair(v, to));         }       }     }   }   int color[maxn];   int first[maxn];   int d[maxn];   vector<int> eu;   int z[shift * 2];   int c;   void dfs2(int v, int tekc, int len, int p = -1) {     used[v] = 1;     color[v] = tekc;     d[tekc] = len;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) continue;       if (used[to]) continue;       if (br.find(make_pair(v, to)) != br.end()) {         eu.push_back(c + 1);         first[c + 1] = eu.size() - 1;         ++c;         dfs2(to, c, len + 1, v);         eu.push_back(tekc);       } else         dfs2(to, tekc, len, v);     }   }   void build() {     for (int i = 0; i < eu.size(); ++i) z[i + shift] = eu[i];     for (int i = eu.size(); i < shift; ++i) z[i + shift] = n + 1;     for (int i = shift - 1; i > 0; --i)       if (d[z[i * 2]] < d[z[i * 2 + 1]])         z[i] = z[i * 2];       else         z[i] = z[i * 2 + 1];   }   int get(int v, int tl, int tr, int l, int r) {     if (l > r) return n + 1;     if (l == tl && r == tr) return z[v];     int tm = (tl + tr) / 2;     int ans1 = get(v * 2, tl, tm, l, min(r, tm));     int ans2 = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     return d[ans1] < d[ans2] ? ans1 : ans2;   }   int main() {     cin >> n >> m;     g.resize(n);     for (int i = 0; i < m; ++i) {       int v, u;       cin >> v >> u;       --v, --u;       g[v].push_back(u);       g[u].push_back(v);     }     dfs(0);     memset(used, 0, sizeof(used));     memset(first, -1, sizeof(first));     eu.push_back(0);     first[0] = 0;     dfs2(0, 0, 0);     d[n + 1] = inf;     build();     int k;     cin >> k;     for (int i = 0; i < k; ++i) {       int s, l;       cin >> s >> l;       --s, --l;       int L = first[color[s]];       int R = first[color[l]];       if (L > R) swap(L, R);       int lca = get(1, 0, shift - 1, L, R);       cout << d[color[s]] + d[color[l]] - 2 * d[lca] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, siz[500010];   vector<int> v[500010];   class DS {    public:     long long dat[2][2];     DS() { memset(dat, 0, sizeof(dat)); }     DS(long long a00, long long a01, long long a10, long long a11) {       dat[0][0] = a00;       dat[0][1] = a01;       dat[1][0] = a10;       dat[1][1] = a11;     }     DS trans() {       return DS(dat[1][0], dat[0][0] + dat[1][1], dat[0][0], dat[0][1]);     }     DS operator*(const DS &t) const {       DS ret;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           for (int k = 0; k + i < 2; k++) {             for (int l = 0; j + l < 2; l++) {               ret.dat[i + k][j + l] += dat[i][j] * t.dat[k][l];             }           }         }       }       return ret;     }   } f[500010], g[500010];   void dfs(int np, int fath) {     f[np] = DS(1, 0, 0, 0);     siz[np] = 1;     for (int &x : v[np]) {       if (x == fath) continue;       dfs(x, np);       siz[np] += siz[x];       f[np] = f[np] * f[x].trans();     }   }   void dfs2(int np, int fath) {     vector<DS> pre;     pre.push_back(DS(1, 0, 0, 0));     for (int i = 0; i < v[np].size(); i++) {       if (v[np][i] == fath)         pre.push_back(pre.back());       else         pre.push_back(pre.back() * f[v[np][i]].trans());     }     DS cur = fath ? g[np].trans() : DS(1, 0, 0, 0);     for (int i = (int)v[np].size() - 1; i >= 0; i--) {       if (v[np][i] == fath) continue;       g[v[np][i]] = cur * pre[i];       dfs2(v[np][i], np);       cur = cur * f[v[np][i]].trans();     }   }   int main() {     scanf( %d , &n);     if (n & 1) {       puts( 0 );       return 0;     }     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 0);     dfs2(1, 0);     long long ans = 0;     for (int i = 2; i <= n; i++) {       if (f[i].dat[1][0] == 1 && g[i].dat[1][0] == 1)         ans += (long long)siz[i] * (n - siz[i]);       else         ans +=             (f[i].dat[0][0] + f[i].dat[1][1]) * (g[i].dat[0][0] + g[i].dat[1][1]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, u, a[300001], x, y;   long double ans = -1.0;   int main() {     cin >> n >> u;     for (int i = 0; i < n; ++i) cin >> a[i];     y = 1;     while (x < n - 2) {       while (y < n - 1 && a[y + 1] - a[x] <= u) ++y;       if (y - x >= 2 && a[y] - a[x] <= u)         ans =             max(ans, (long double)(a[y] - a[x + 1]) / (long double)(a[y] - a[x]));       ++x;     }     printf( %.9Lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n, m, cnt, belong[N];   vector<int> g[N], ans[N];   int get(int x) { return belong[x] ? belong[x] = get(belong[x]) : x; }   void dfs(int i) {     ans[cnt].push_back(i);     belong[i] = i + 1;     for (int j = get(1), k = 0; j <= n; j = get(j + 1)) {       for (; k < g[i].size() && g[i][k] < j; k++)         ;       if (k < g[i].size() && g[i][k] == j) continue;       dfs(j);     }   }   int main() {     scanf( %d%d , &n, &m);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= n; i++)       if (!belong[i]) {         dfs(i);         cnt++;       }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) {       printf( %u , ans[i].size());       for (int j = 0; j < ans[i].size(); j++) printf(  %d , ans[i][j]);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int q, n;   int a[100010], b[100010];   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) scanf( %d , &b[i]);       int pos = 0, dis = 0, flag1 = 0, flag2 = 0;       for (int i = 1; i <= n; i++) {         if (a[i] != b[i] && flag1 == 0) {           pos = i;           dis = b[i] - a[i];           if (dis < 0) {             flag2 = 1;             break;           }           flag1 = 1;         } else if (a[i] != b[i] && flag1 == 1) {           if (b[i] - a[i] != dis || i != pos + 1) {             flag2 = 1;             break;           } else             pos = i;         }       }       if (flag2)         printf( NO n );       else         printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9;   const double eps = 1e-9;   int x[3], y[3];   int main() {     int i;     vector<pair<int, int> > V(8);     set<int> X;     set<int> Y;     for (i = 0; i < 8; i++) {       cin >> V[i].first >> V[i].second;       X.insert(V[i].first);       Y.insert(V[i].second);     }     i = 0;     for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); ++it)       x[i++] = *it;     i = 0;     for (__typeof((Y).begin()) it = (Y).begin(); it != (Y).end(); ++it)       y[i++] = *it;     vector<pair<int, int> > C(8);     C[0] = make_pair(x[0], y[0]);     C[1] = make_pair(x[0], y[1]);     C[2] = make_pair(x[0], y[2]);     C[3] = make_pair(x[1], y[0]);     C[4] = make_pair(x[1], y[2]);     C[5] = make_pair(x[2], y[0]);     C[6] = make_pair(x[2], y[1]);     C[7] = make_pair(x[2], y[2]);     sort((V).begin(), (V).end());     if (((int)(X).size()) != 3 || ((int)(Y).size()) != 3 || V != C)       puts( ugly );     else       puts( respectable );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[4000];   int ans[4000][4000];   int main() {     cin >> n;     map<int, int> r;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (r.find(a[i]) == r.end()) {         int k = r.size();         r[a[i]] = k;       }       a[i] = r[a[i]];     }     int m = r.size();     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ans[j][a[i]] + 1 > ans[a[i]][j]) {           ans[a[i]][j] = ans[j][a[i]] + 1;         }       }     }     int best = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] > best) {           best = ans[i][j];         }       }     }     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[100001], b[100001];   vector<long long int> v;   map<long long int, long long int> assign;   pair<long long int, long long int> dp[1001][7001];   inline long long int gcd(long long int a, long long int b) {     long long int tmp;     while (b) {       tmp = a % b;       a = b;       b = tmp;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     ;     cin.tie(0);     ;     long long int i, j, n, k, x, y, temp, sz;     cin >> n >> k;     temp = k;     for (i = 1; i <= n; i++) {       cin >> a[i];       b[i] = gcd(a[i], k);       temp = temp / gcd(temp, a[i]);     }     if (temp != 1) {       cout <<  -1 ;       return 0;     }     if (k == 1) {       cout <<  1             <<   n ;       cout << min_element(a + 1, a + n + 1) - a;       return 0;     }     for (i = 1; i * i <= k; i++) {       if (k % i) continue;       v.push_back(i);       if (i != (k / i)) v.push_back(k / i);     }     sort(v.begin(), v.end());     sz = v.size();     for (i = 0; i < sz; i++) assign[v[i]] = i;     for (i = 1; i < sz; i++) dp[0][i] = make_pair(1000000000000, 0);     dp[0][0] = make_pair(0, 0);     for (i = 1; i <= n; i++) {       for (j = 0; j < sz; j++) {         dp[i][j] = dp[i - 1][j];         x = assign[v[j] / gcd(v[j], b[i])];         if (dp[i][j] >             make_pair(dp[i - 1][x].first + 1, dp[i - 1][x].second + a[i]))           dp[i][j] =               make_pair(dp[i - 1][x].first + 1, dp[i - 1][x].second + a[i]);       }     }     cout << dp[n][sz - 1].first <<   n ;     x = k;     for (i = n; i >= 1; i--) {       if (dp[i][assign[x]] == dp[i - 1][assign[x]]) continue;       cout << i <<    ;       x = x / gcd(x, b[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int N = 200111;   struct node {     int i, j;     long long mn, ad = 0;     node *l, *r;     node(long long *a, int i, int j) : i(i), j(j) {       if (j - i == 1) {         l = r = NULL;         mn = a[i];       } else {         int k = i + j >> 1;         l = new node(a, i, k);         r = new node(a, k, j);         combine();       }     }     inline void combine() { mn = min(l->mn, r->mn); }     void visit() {       if (ad) {         mn += ad;         if (l) l->ad += ad, r->ad += ad;         ad = 0;       }     }     void inc(int I, int J, long long a) {       if (I <= i && j <= J) {         ad += a;         visit();       } else {         visit();         if (!(J <= i || j <= I)) {           l->inc(I, J, a);           r->inc(I, J, a);           combine();         }       }     }     int find() {       visit();       if (mn > 0) return INF;       if (!l) {         return mn == 0 ? i : INF;       } else {         int ans = INF;         if (ans >= INF) ans = l->find();         if (ans >= INF) ans = r->find();         return ans;       }     }   };   long long a[N], s[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       s[i + 1] = s[i] + a[i];     }     for (int i = 0; i < n; i++) {       s[i] -= a[i];     }     node *t = new node(s, 0, n);     while (q--) {       int i;       long long v;       scanf( %d%lld , &i, &v);       long long d = v - a[--i];       t->inc(i, i + 1, -d);       t->inc(i + 1, n, +d);       t->visit();       a[i] += d;       int ans = t->find();       printf( %d n , ans >= INF ? -1 : ans + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2501;   mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());   int n, p[2 * N], a[N][N], cur;   void no() {     puts( NOT MAGIC );     exit(0);   }   struct edge {     int u, v, w;     edge(int a = 0, int b = 0, int c = 0) {       u = a;       v = b;       w = c;     }     bool operator<(const edge &a) const { return w < a.w; }   };   int get(int u) { return u == p[u] ? u : p[u] = get(p[u]); }   vector<edge> e;   vector<pair<int, int>> g[2 * N];   void dfs(int u, int p, int mx) {     if (u >= n && a[cur][u - n] > mx) no();     for (auto i : g[u])       if (i.first != p) dfs(i.first, u, max(mx, i.second));   }   int main() {     for (int i = 0; i < 2 * N; i++) p[i] = i;     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         e.push_back(edge(i, n + j, a[i][j]));       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (a[i][j] != a[j][i] || i == j && a[i][j]) no();       }     sort(e.begin(), e.end());     for (auto i : e) {       int a = get(i.u);       int b = get(i.v);       if (a != b) {         p[a] = b;         g[i.u].push_back({i.v, i.w});         g[i.v].push_back({i.u, i.w});       }     }     for (int i = 0; i < n; i++) {       cur = i;       dfs(i, -1, 0);     }     puts( MAGIC );   }
#include <bits/stdc++.h>   using ll = long long;   const ll maxn = 1234;   const ll inf = 1e9 + 7;   int main(int argc, char *argv[]) {     ll n, m, a[maxn];     std::cin >> n >> m;     ll cur = 0, maxx = 0, minn = 0;     for (int i = 0; i < n; i++) {       std::cin >> a[i];       cur += a[i];       maxx = std::max(maxx, cur);       minn = std::min(minn, cur);     }     ll ans = maxx - minn;     if (maxx - minn > m) {       std::cout << 0;     } else {       std::cout << m - (maxx - minn) + 1;     }   }
#include <bits/stdc++.h>   using namespace std;   void A() {     cout <<  tokitsukaze  << endl;     exit(0);   }   void B() {     cout <<  quailty  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     set<int> p[2];     for (int i = 0; i < n; ++i) {       p[s[i] -  0 ].insert(i);     }     int m[2], M[2];     if (p[0].empty() || p[1].empty()) {       A();     }     m[0] = *p[0].begin();     M[0] = *--p[0].end();     m[1] = *p[1].begin();     M[1] = *--p[1].end();     if (M[0] - m[0] + 1 <= k || M[1] - m[1] + 1 <= k) {       A();     }     bool b = true;     for (int i = 0; i < n - k + 1; ++i) {       bool ok = false;       int l, r;       l = min(m[0], i);       r = max(M[0], i + k - 1);       if (r - l + 1 <= k) {         ok = true;       }       if (m[1] < i) {         l = m[1];       } else {         l = *p[1].lower_bound(i + k);       }       if (M[1] >= i + k) {         r = M[1];       } else {         r = *--p[1].lower_bound(i);       }       if (r - l + 1 <= k) {         ok = true;       }       if (!ok) {         b = false;       }       ok = false;       l = min(m[1], i);       r = max(M[1], i + k - 1);       if (r - l + 1 <= k) {         ok = true;       }       if (m[0] < i) {         l = m[0];       } else {         l = *p[0].lower_bound(i + k);       }       if (M[0] >= i + k) {         r = M[0];       } else {         r = *--p[0].lower_bound(i);       }       if (r - l + 1 <= k) {         ok = true;       }       if (!ok) {         ok = false;       }     }     if (b) {       B();     }     cout <<  once again  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int f = 0, x = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       f = (f << 1) + (f << 3) + ch -  0 ;       ch = getchar();     }     return f * x;   }   int a[200005], b[600005], m, n;   bool check(int x) {     int l = 1, r = 3 * n;     for (int i = 1; i <= n; i++) {       while (a[i] - b[l] > x) l++;       while (b[r] - a[i] > x) r--;       l++;       r++;     }     return l <= r;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 1; i <= n; i++) {       b[i + n] = b[i] - m;       b[i + 2 * n] = b[i] + m;     }     sort(b + 1, b + 3 * n + 1);     sort(a + 1, a + n + 1);     int l = 0, r = (m + 1) >> 1, ans = 0;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     cout << ans;   }
#include <bits/stdc++.h>   const int MAXN = 100100;   char S[MAXN];   char T[MAXN];   int aS[MAXN], aT[MAXN];   int bS[MAXN], bT[MAXN];   bool go() {     int leftS, rightS, leftT, rightT;     scanf( %d %d %d %d , &leftS, &rightS, &leftT, &rightT);     int lengthS = rightS - leftS + 1;     int lengthT = rightT - leftT + 1;     int as = aS[rightS];     if (as > lengthS) as = lengthS;     int at = aT[rightT];     if (at > lengthT) at = lengthT;     int bs = bS[rightS] - bS[leftS - 1];     int bt = bT[rightT] - bT[leftT - 1];     if (bs % 2 != bt % 2) {       return false;     }     if (bs > bt) {       return false;     }     if (as < at) {       return false;     }     if (bs == bt) {       if (as % 3 != at % 3) {         return false;       }     } else {       if (bs == 0 && as == at) {         return false;       }     }     return true;   }   void goA(char *s, int *ar) {     int run = 0;     for (int i = 1; s[i]; ++i) {       if (s[i] ==  A )         ++run;       else         run = 0;       ar[i] = run;     }   }   void goB(char *s, int *ar) {     int run = 0;     for (int i = 1; s[i]; ++i) {       if (s[i] ==  B  || s[i] ==  C ) ++run;       ar[i] = run;     }   }   int main() {     scanf( %s , S + 1);     scanf( %s , T + 1);     goA(S, aS);     goA(T, aT);     goB(S, bS);     goB(T, bT);     int q;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       if (go()) {         printf( 1 );       } else {         printf( 0 );       }     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       cout << 2 << endl;       int prev = (n + n - 1) / 2;       if ((n + n - 1) % 2 != 0) prev++;       cout << n <<     << n - 1 << endl;       for (int i = n - 2; i >= 1; i--) {         int ad = 0;         cout << i <<     << prev << endl;         if ((i + prev) % 2 != 0) ad = 1;         prev = (i + prev) / 2 + ad;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int l, r;     cin >> l >> r;     long long int p = 1;     long long int sum = 0;     for (long long int i = 0; i < 32; i++) {       for (long long int j = 0; j < 32; j++) {         long long int x = pow(2, i) * pow(3, j);         if (x > r) break;         if (x >= l && x <= r) sum++;       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int lcm(int a, int b) { return (a * b) / gcd(a, b); }   int fact(int n) {     if (n == 0 || n == 1)       return 1;     else       return n * fact(n - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, a = 0, b = 0, l1 = 0, l2 = 0, c = 0, k = 0;       cin >> n;       deque<int> q;       for (int i = 0, x; i < n; i++) {         cin >> x;         q.push_back(x);       }       while (!q.empty()) {         while (l1 <= l2 && !q.empty()) {           a += q.front();           l1 += q.front();           q.pop_front();           k = 1;         }         c += k;         k = l2 = 0;         while (l2 <= l1 && !q.empty()) {           b += q.back();           l2 += q.back();           q.pop_back();           k = 1;         }         c += k;         k = l1 = 0;       }       cout << c <<     << a <<     << b << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, st[N], fn[N], timer, ans[N];   vector<int> adj[N], vec[N];   struct node {     long long sum, lazy, sz, one;     node() { sum = one = sz = lazy = 0; }   } seg[N << 2];   void dfs1(int v, int p = -1) {     st[v] = timer++;     for (auto u : adj[v]) {       if (u == p) continue;       dfs1(u, v);     }     fn[v] = timer;   }   void build(int id = 1, int b = 0, int e = n) {     if (e - b == 1) {       seg[id].sz = 1;       return;     }     int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;     build(lc, b, mid);     build(rc, mid, e);     seg[id].sz = seg[lc].sz + seg[rc].sz;     return;   }   void add(int l, int r, int val, int id = 1, int b = 0, int e = n) {     if (l >= e || b >= r) return;     if (l <= b && e <= r) {       seg[id].one += val;       return;     }     int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;     add(l, r, val, lc, b, mid);     add(l, r, val, rc, mid, e);     seg[id].sum = ((seg[lc].one) ? seg[lc].sz : seg[lc].sum) +                   ((seg[rc].one) ? seg[rc].sz : seg[rc].sum);     return;   }   void dfs2(int v, int p = -1) {     if (vec[v].size()) vec[v].push_back(v);     for (auto u : vec[v]) {       int l = st[u], r = fn[u];       add(l, r, 1);     }     ans[v] = ((seg[1].one) ? n : seg[1].sum);     if (ans[v]) ans[v]--;     for (auto u : adj[v]) {       if (u == p) continue;       dfs2(u, v);     }     for (auto u : vec[v]) {       int l = st[u], r = fn[u];       add(l, r, -1);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int v, u;       cin >> v >> u;       v--, u--;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs1(0);     build();     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       int l = st[b], r = fn[b];       vec[a].push_back(b);       l = st[a], r = fn[a];       vec[b].push_back(a);     }     dfs2(0);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout <<   n ;   }