func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, l, r;   vector<pair<int, int> > G[100005];   int seq[100005], cnts, siz[100005], rch[100005], num[100005];   bool vis[100005];   int rt, Min;   void dfs(int now, int ff, int tsz) {     int Max = 0;     siz[now] = 1;     rch[now] = 0;     for (int i = 0, v, sz = G[now].size(); i < sz; i++)       if ((v = G[now][i].first) != ff && !vis[v]) {         dfs(v, now, tsz);         rch[now] = max(rch[now], rch[v] + 1);         siz[now] += siz[v];         Max = max(Max, siz[v]);       }     Max = max(Max, tsz - siz[now]);     if (Max < Min) Min = Max, rt = now;   }   int Gert(int now, int tsz) {     Min = 0x3f3f3f3f;     dfs(now, -1, tsz);     return rt;   }   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     return rch[a.first] < rch[b.first];   }   void setsiz(int now, int ff) {     siz[now] = 1, rch[now] = 0;     for (int i = 0, sz = G[now].size(), v; i < sz; i++)       if ((v = G[now][i].first) != ff && !vis[v]) {         setsiz(v, now);         siz[now] += siz[v];         rch[now] = max(rch[now], rch[v] + 1);       }   }   void Solve(int now) {     seq[++cnts] = now;     setsiz(now, -1);     vis[now] = 1;     rch[now] = 0;     sort(G[now].begin(), G[now].end(), cmp);     for (int v, i = 0, sz = G[now].size(); i < sz; i++)       if (!vis[(v = G[now][i].first)]) Solve(Gert(v, siz[v]));   }   int f[100005], g[100005], floc[100005], gloc[100005], ansx, ansy;   int Maxdep;   void ser(int now, int ff, int dist, int cost, int Lim) {     Maxdep = max(Maxdep, dist);     if (cost > g[dist]) g[dist] = cost, gloc[dist] = now;     for (int i = 0, sz = G[now].size(), v; i < sz; i++)       if ((v = G[now][i].first) != ff && !vis[v])         ser(v, now, dist + 1, cost + (G[now][i].second >= Lim ? 1 : -1), Lim);   }   int Q[100005], L, R;   bool check(int Lim) {     memset(vis, 0, sizeof vis);     memset(f, -0x3f, sizeof f);     memset(g, -0x3f, sizeof g);     f[0] = 0;     int premaxdep = 0;     for (int u, id = 1; id <= n; id++) {       for (int i = 1; i <= premaxdep; i++) f[i] = -0x3f3f3f3f, g[i] = -0x3f3f3f3f;       premaxdep = 0;       vis[u = seq[id]] = 1;       floc[0] = u;       for (int predep = 0, i = 0, v, sz = G[u].size(); i < sz; i++)         if (!vis[v = G[u][i].first]) {           for (int j = 1; j <= predep; j++) g[j] = -0x3f3f3f3f;           Maxdep = 0;           ser(v, -1, 1, G[u][i].second >= Lim ? 1 : -1, Lim);           L = R = 0;           for (int j = 0, k = min(r, Maxdep); j <= predep; j++) {             for (; j + k >= l && k >= 0; k--) {               for (; L < R && g[k] >= g[Q[R - 1]]; R--)                 ;               Q[R++] = k;             }             for (; L < R && Q[L] + j > r; L++)               ;             if (L < R && f[j] + g[Q[L]] >= 0) {               ansx = floc[j];               ansy = gloc[Q[L]];               return 1;             }           }           for (int j = 1; j <= Maxdep; j++)             if (f[j] < g[j]) f[j] = g[j], floc[j] = gloc[j];           predep = Maxdep;           premaxdep = max(premaxdep, Maxdep);         }     }     return 0;   }   int main() {     int u, v, w;     scanf( %d%d%d , &n, &l, &r);     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &u, &v, &w);       G[u].push_back(make_pair(v, w));       G[v].push_back(make_pair(u, w));     }     Solve(Gert(1, n));     int L = 0, R = 1000000000, Mid;     while (L < R) {       Mid = (L + R + 1) >> 1;       if (check(Mid))         L = Mid;       else         R = Mid - 1;     }     check(L);     printf( %d %d n , ansx, ansy);   }   