malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct sort_pred {     bool operator()(const std::pair<int, int> &left,                     const std::pair<int, int> &right) {       return right.first > left.first;     }   };   int n, m, k, t;   int r = 0;   vector<bool> visited;   vector<vector<int>> v;   vector<int> distanc;   queue<int> q;   map<pair<int, int>, int> mp;   vector<bool> chosen;   void bfs(int first) {     visited[first] = true;     q.push(first);     while (!q.empty()) {       int s = q.front();       q.pop();       for (auto u : v[s]) {         if (distanc[s] - mp[make_pair(s, u)] >= 0 &&             distanc[s] - mp[make_pair(s, u)] > distanc[u]) {           if (!visited[u]) r++;           visited[u] = true;           distanc[u] = distanc[s] - mp[make_pair(s, u)];           if (chosen[u]) distanc[u] = t;           q.push(u);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     map<int, int> mp;     vector<int> b(n);     for (int i = 0; i < n; i++) {       int first;       cin >> first;       mp[first] = i + 1;     }     for (int i = 0; i < n; i++) {       int first;       cin >> first;       cout << mp[first] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 1e9 + 5;   long long powmod(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ret;   }   const int maxn = 3e5 + 5;   long long a[maxn];   int n, m;   int q[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long tot = 0;     for (int i = 0; i <= n - 1; i++) {       cin >> a[i];       tot += a[i];     }     sort(a, a + n);     cin >> m;     for (int i = 0; i <= m - 1; i++) {       cin >> q[i];       cout << tot - a[n - q[i]] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1002000, CAN = 34;   int n, m, p, vis[MAXN], pr[MAXN], pcnt;   char w1[MAXN], w2[MAXN];   vector<int> can[300];   int muln(int x, int y) { return 1LL * x * y % p; }   int mo(int x) {     while (x >= p) x -= p;     while (x < 0) x += p;     return x;   }   int qpow(int x, int y) {     int ret = 1;     for (; y; y >>= 1, x = muln(x, x))       if (y & 1) ret = muln(ret, x);     return ret;   }   struct poly {     int deg;     vector<int> a;     poly(int x = 0) : deg(x) { a.resize(x + 1, 0); }     int& operator[](int idx) { return a[idx]; }     void print(string s) {       cerr <<  Poly   << s <<  :  ;       for (auto g : a) printf( %d  , g);       cerr << endl;     }     int at(int x) {       x = mo(x);       int ret = 0;       for (int i = deg; i >= 0; --i) ret = mo(muln(ret, x) + mo(a[i]));       return ret;     }     void norm() {       for (auto& g : a) g = mo(g);     }   } I;   void sieve() {     for (int i = 2; i <= 1000000; ++i) {       if (!vis[i]) {         pr[++pcnt] = i;       }       for (int j = 1; j <= pcnt && i * pr[j] <= 1000000; ++j) {         vis[i * pr[j]] = true;         if (i % pr[j] == 0) break;       }     }     for (int k = 1, i = pr[k]; k <= pcnt; i = pr[++k]) {       if (i > m)         for (int j = 1; j <= CAN; ++j)           if ((i - 1) % pr[j] == 0) can[j].push_back(i);     }   }   void sol(int opt) {     int d = pr[opt];     poly a(d - 1);     for (int i = 0; i < n; ++i) a[i % d] += I[i];     for (auto pri : can[opt]) {       p = pri;       int rr = 2;       while (qpow(rr, (p - 1) / d) == 1) rr++;       rr = qpow(rr, (p - 1) / d);       for (int Cnt = 1; Cnt < d; ++Cnt) {         int r = qpow(rr, Cnt);         if (r < 2 || r > p - 2) continue;         int val = a.at(r);         if (val == 0) {           printf( %d %d n , p, r);           exit(0);         }       }     }   }   int main() {     scanf( %d%d%s%s , &n, &m, w1, w2);     sieve();     I = poly(n - 1);     for (int i = 0; i < n; ++i) I[i] = w1[i] - w2[i];     for (int i = 1; i <= CAN; ++i) sol(i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100007], ans[100007], vis[100007];   int count(int x) {     int cnt = 0, now = 0;     memset(vis, 255, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (vis[a[i]] == now) continue;       vis[a[i]] = now;       if (++cnt > x) {         cnt = 1;         vis[a[i]] = ++now;       }     }     return now + 1;   }   void work(int l, int r) {     if (l > r) return;     int cnt1 = count(l), cnt2 = count(r);     if (cnt1 == cnt2) {       for (int i = l; i <= r; i++) ans[i] = cnt1;       return;     }     ans[l] = cnt1;     ans[r] = cnt2;     int mid = (l + r) >> 1;     work(l + 1, mid);     work(mid + 1, r - 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     work(1, n);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> good, bad;     for (long long i = 0; i < n; i++) {       long long val = sqrt(a[i]);       if (val * val == a[i])         good.push_back(a[i]);       else         bad.push_back(a[i]);     }     long long sz1 = good.size(), sz2 = bad.size();     if (sz1 == sz2) {       cout << 0 <<   n ;     } else if (sz1 > sz2) {       long long nz = 0;       for (auto it : good) {         if (it) nz++;       }       long long req = (sz1 - sz2) / 2;       if (nz >= req)         cout << req <<   n ;       else         cout << nz + (req - nz) * 2 <<   n ;     } else {       vector<long long> ans;       long long req = (sz2 - sz1) / 2;       for (auto it : bad) {         long long val = sqrt(it);         long long down = it - val * val, up = (val + 1) * (val + 1) - it;         ans.push_back(min(down, up));       }       sort(ans.begin(), ans.end());       long long fans = 0;       for (long long i = 0; i < req; i++) {         fans += ans[i];       }       cout << fans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = (1 << 22) + 5;   int n, m;   bool is[MAX], seen[MAX];   int conj(int x) {     int r = 0;     for (int i = 0; i < n; ++i)       if (!(x & (1 << i))) r += (1 << i);     return r;   }   void dfs(int st, bool p = 0) {     if (seen[st]) return;     seen[st] = 1;     if (is[st]) dfs(conj(st), 1);     if (p) {       for (int i = 0; i < n; ++i)         if (st & (1 << i)) {           dfs(st - (1 << i), 1);         }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> m;     vector<int> st((1 << n) + 1, 0);     vector<bool> lz((1 << n) + 1, 0);     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       is[x] = 1;     }     int cnt = 0;     for (int i = 0; i < (1 << n); ++i) {       if (!seen[i] && is[i]) {         dfs(i);         ++cnt;       }     }     cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int n, x;     cin >> n;     vector<vector<long long int> > a(n);     for (long long int i = 0; i < n; i++) {       cin >> x;       for (long long int j = 0; j < x; j++) {         long long int tp;         cin >> tp;         a[i].push_back(tp);       }     }     long long int a1 = 0, b = 0;     vector<long long int> q;     for (long long int i = 0; i < n; i++) {       long long int f = a[i].size();       if (f % 2 != 0) {         for (long long int j = 0; j < (f - 1) / 2; j++) {           a1 += a[i][j];         }         for (long long int j = (f - 1) / 2 + 1; j < f; j++) {           b += a[i][j];         }         q.push_back(a[i][(f - 1) / 2]);       } else {         for (long long int j = 0; j < f / 2; j++) {           a1 += a[i][j];         }         for (long long int j = f / 2; j < f; j++) {           b += a[i][j];         }       }     }     sort(q.begin(), q.end(), greater<long long int>());     for (long long int k = 0; k < q.size(); k++) {       if (k % 2 == 0)         a1 += q[k];       else         b += q[k];     }     cout << a1 <<     << b;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 3 * (int)1e5 + 100;   int b[maxN];   int t[4 * maxN];   int a[maxN];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = a[tl];       return;     }     int tm = (tl + tr) / 2;     build(v + v, tl, tm);     build(v + v + 1, tm + 1, tr);     t[v] = min(t[v + v], t[v + v + 1]);   }   void upd(int v, int tl, int tr, int pos, int val) {     if (tl == tr) {       t[v] = val;       return;     }     int tm = (tl + tr) / 2;     if (pos <= tm)       upd(v + v, tl, tm, pos, val);     else       upd(v + v + 1, tm + 1, tr, pos, val);     t[v] = min(t[v + v], t[v + v + 1]);   }   const int INF = (int)1e9 + 100;   int get(int v, int tl, int tr, int l, int r) {     if (l > r) return INF;     if (tl == l && tr == r) {       return t[v];     }     int tm = (tl + tr) / 2;     return min(get(v + v, tl, tm, l, min(r, tm)),                get(v + v + 1, tm + 1, tr, max(l, tm + 1), r));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       set<pair<int, int> > s;       for (int i = 1; i <= n; i++) {         cin >> a[i];         s.insert(make_pair(a[i], i));       }       bool ok = true;       build(1, 1, n);       for (int i = 1; i <= n; i++) {         cin >> b[i];         if (!ok) continue;         auto it = s.lower_bound(make_pair(b[i], -1));         if (it == s.end() || ((it->first) != b[i])) {           ok = false;           continue;         }         int ind = (it->second);         s.erase(it);         if (b[i] != get(1, 1, n, 1, ind)) {           ok = false;         }         upd(1, 1, n, ind, INF);       }       if (ok)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[11];   int main() {     int i, n, m, x;     while (scanf( %d , &a[0]) > 0) {       int c[33] = {0};       c[a[0]]++;       for ((i) = 0; (i) < (5); (i)++) {         scanf( %d , &a[i + 1]);         c[a[i + 1]]++;       }       bool f = 0;       int mx = 0;       for ((i) = 0; (i) < (11); (i)++) {         mx = max(mx, c[i]);         c[i] = c[i] % 4;         if (c[i] == 2) f = 1;       }       if (mx < 4)         printf( Alien n );       else if (f)         printf( Elephant n );       else         printf( Bear n );     }     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 2000 + 10;   const int INF = std::numeric_limits<int>::max();   const double EPS = 1e-6;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   int a[MAXN][MAXN];   std::deque<std::pair<std::pair<int, int>, int>> q;   using std::cin;   using std::cout;   using std::endl;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     int n, m;     cin >> n >> m;     int r, c;     cin >> r >> c;     int x, y;     cin >> x >> y;     for (int i = 0; i <= n + 1; ++i) {       for (int j = 0; j <= m + 1; ++j) {         a[i][j] = -1;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         char c;         cin >> c;         if (c ==  . ) a[i][j] = INF;       }     }     q.push_back({{r, c}, 0});     a[r][c] = 0;     while (!q.empty()) {       int cur_x = q.front().first.first, cur_y = q.front().first.second,           cur_step = q.front().second;       q.pop_front();       for (int i = 0; i < 4; ++i) {         if (a[cur_x + dx[i]][cur_y + dy[i]] > cur_step + (dy[i] == -1)) {           a[cur_x + dx[i]][cur_y + dy[i]] = cur_step + (dy[i] == -1);           if (dy[i] == -1)             q.push_back({{cur_x + dx[i], cur_y + dy[i]}, cur_step + 1});           else             q.push_front({{cur_x + dx[i], cur_y + dy[i]}, cur_step});         }       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j] != -1) {           if (a[i][j] <= x && a[i][j] + j - c <= y) {             ++ans;           }         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int g[405][405];   vector<int> v[405];   double ans;   double gai[405];   double pos[405];   double suan(int yi, int juli) {     memset(gai, 0, sizeof(gai));     for (int i = 1; i <= n; i++) {       if (g[i][yi] == juli) {         for (int j = 0; j < (int)v[i].size(); j++) {           gai[v[i][j]] += 1.0 / n / (int)v[i].size();         }       }     }     vector<int> r;     r.clear();     for (int i = 1; i <= n; i++)       if (gai[i]) r.push_back(i);     double ret = 0;     for (int i = 1; i <= n; i++) {       double tmp = 0;       for (int j = 0; j < (int)r.size(); j++) {         pos[g[i][r[j]]] = max(pos[g[i][r[j]]], gai[r[j]]);       }       for (int j = 0; j < (int)r.size(); j++) {         tmp += pos[g[i][r[j]]];         pos[g[i][r[j]]] = 0;       }       ret = max(ret, tmp);     }     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (i != j) g[i][j] = 199912310;     }     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d , &x, &y);       g[x][y] = 1;       g[y][x] = 1;       v[x].push_back(y);       v[y].push_back(x);     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++)           g[i][j] = g[j][i] = min(g[i][j], g[i][k] + g[k][j]);       }     }     for (int i = 1; i <= n; i++) {       double now = 0;       for (int dist = 0; dist < n; dist++) {         int cnt = 0;         for (int j = 1; j <= n; j++) {           if (g[i][j] == dist) cnt++;         }         if (!cnt) continue;         double p = 1.0 / n;         double q = suan(i, dist);         now += max(p, q);       }       ans = max(ans, now);     }     printf( %.8lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool voltea;   int A[100005], B[100005], I[100005], D[100005], R[100005], ctos, hay, x, y, mid,       en;   int Z[100005], grande;   void lis() {     B[1] = A[1];     if (voltea)       D[ctos] = 1;     else       I[1] = 1;     hay = 1;     for (int i = 2; i <= ctos; i++) {       if (A[i] > B[hay]) {         ++hay;         B[hay] = A[i];         en = hay;       } else {         x = 1;         y = hay;         while (x < y) {           mid = (x + y) / 2;           if (B[mid] < A[i]) {             x = mid + 1;           } else {             y = mid;           }         }         B[x] = A[i];         en = x;       }       if (voltea) {         D[ctos - i + 1] = en;       } else {         I[i] = en;       }     }   }   int main() {     scanf( %d , &ctos);     for (int i = 1; i <= ctos; i++) {       scanf( %d , &A[i]);     }     lis();     voltea = true;     x = 1;     y = ctos;     while (x < y) {       swap(A[x], A[y]);       A[x] *= -1;       A[y] *= -1;       ++x;       --y;     }     if (x == y) {       A[x] *= -1;     }     lis();     grande = 1;     for (int i = 1; i <= ctos; i++) {       if (I[i] + D[i] - 1 > grande) {         grande = I[i] + D[i] - 1;       }     }     for (int i = 1; i <= ctos; i++) {       if (I[i] + D[i] - 1 == grande) {         Z[I[i]]++;       } else {         R[i] = 1;       }     }     for (int i = 1; i <= ctos; i++) {       if (R[i] == 0) {         R[i] = 2;         if (Z[I[i]] == 1) {           R[i] = 3;         }       }       printf( %d , R[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     if (a >= c || b >= c) {       cout <<  0 ;     } else if (a <= 0 && b <= 0) {       cout <<  -1 ;     } else {       long long int count = 0;       while (a < c && b < c) {         if (a > b) {           swap(a, b);         } else if (a < 0) {           count += (abs(a) / b + (abs(a) % b != 0));           if (abs(a) % b) {             long long int r = abs(a) % b;             a = (b - r);           } else {             a = 0;           }         } else {           long long int p = b;           b += a;           a = p;           count++;         }       }       cout << count;     }   }
#include <bits/stdc++.h>   char map[2][9][9];   int now[2][9][9], dx[] = {-1, -1, 0, 1, 1, 1, 0, -1, 0},                     dy[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};   int main() {     for (int i = 0; i < 8; i++) scanf( %s , map[0][i]);     bool a = 0;     now[a][7][0] = 1;     int sta = 0;     while (sta == 0) {       memset(now[!a], 0, sizeof(now[!a]));       memset(map[!a], 0, sizeof(map[!a]));       for (int i = 1; i < 8; i++)         for (int j = 0; j < 8; j++)           if (map[a][i - 1][j] ==  S ) map[!a][i][j] =  S ;       for (int i = 0; i < 8; i++)         for (int j = 0; j < 8; j++)           if (now[a][i][j])             for (int k = 0; k < 9; k++) {               int x = i + dx[k], y = j + dy[k];               if (x < 0 || x > 7 || y < 0 || y > 7 || map[a][x][y] ==  S )                 continue;               now[!a][x][y] = 1;             }       if (now[!a][0][7]) {         sta = 1;         continue;       }       bool alive = 0;       for (int i = 0; i < 8; i++)         for (int j = 0; j < 8; j++)           if (map[!a][i][j] ==  S )             now[!a][i][j] = 0;           else if (now[!a][i][j] == 1)             alive = 1;       if (alive == 0) sta = 2;       a = !a;     }     puts(sta == 1 ?  WIN  :  LOSE );   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                            {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   int par[200010], r[200010], lar[200010];   void init() {     for (int i = 0; i < 200010; i++) {       par[i] = i;       r[i] = 0;       lar[i] = 1;     }   }   int find(int x) {     if (par[x] == x) return x;     return par[x] = find(par[x]);   }   bool same(int x, int y) { return find(x) == find(y); }   void unit(int x, int y) {     if (same(x, y)) return;     x = find(x);     y = find(y);     if (r[x] < r[y]) {       par[x] = y;       lar[y] += lar[x];     } else {       par[y] = x;       lar[x] += lar[y];       if (r[x] == r[y]) {         r[x]++;       }     }   }   int main() {     static int n;     static int a[200010];     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     init();     bool used[200010];     for (int i = 0; i < 200010; i++) {       used[i] = false;     }     vector<pair<int, int> > vec;     for (int i = 1; i <= n; i++) {       vec.push_back(pair<int, int>(a[i], i));     }     sort(vec.begin(), vec.end());     reverse(vec.begin(), vec.end());     int ans[200010];     int k = 1;     for (int i = 0; i < vec.size(); i++) {       pair<int, int> p = vec[i];       used[p.second] = true;       if (used[p.second - 1]) {         unit(p.second, p.second - 1);       }       if (used[p.second + 1]) {         unit(p.second, p.second + 1);       }       for (; k <= lar[find(p.second)]; k++) {         ans[k] = p.first;       }     }     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i]);     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 7;   int n;   map<pair<int, int>, int> id;   vector<int> g[N];   long double rep(long double x) {     if (x >= 2) {       x -= 2;     }     return x;   }   void dfs(int a, int p = 0, long double t = 0) {     int deg = (int)g[a].size();     long double jump = 2 / (long double)deg;     for (auto &b : g[a]) {       if (b == p) continue;       t = rep(t + jump);       cout << 1 <<     << id[{a, b}] <<    ;       if (t <= 1) {         cout << b <<     << a <<     << fixed << setprecision(6) << 1 - t <<   n ;       } else {         cout << a <<     << b <<     << fixed << setprecision(6) << 1 - rep(t + 1)              <<   n ;       }       dfs(b, a, rep(t + 1));     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       id[{x, y}] = i;       id[{y, x}] = i;       g[x].push_back(y);       g[y].push_back(x);     }     int root = 1;     cout << n - 1 <<   n ;     dfs(root);   }
#include <bits/stdc++.h>   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x7f7f7f7f;   const double inf = 1e50;   template <class T>   inline T minx(T a, T b) {     return (a == -1 || b < a) ? b : a;   }   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   inline T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <class T>   inline T getbit(T n) {     return n ? (1 + getbit(n & (n - 1))) : 0;   }   template <class T>   inline T lowbit(T n) {     return n & (-n);   }   using namespace std;   pair<double, double> parse(double x, double y) { return make_pair(x, y); }   int main() {     int i, j, k;     pair<double, double> A, B, C;     double x, y;     double dx, dy, tx, ty;     while (cin >> x >> y) {       A = parse(x, y);       cin >> x >> y;       B = parse(x, y);       cin >> x >> y;       C = parse(x, y);       dx = B.first - A.first;       dy = B.second - A.second;       tx = C.first - B.first;       ty = C.second - B.second;       double res = dx * ty - dy * tx;       if (res == 0)         puts( TOWARDS );       else if (res > 0)         puts( LEFT );       else         puts( RIGHT );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000009;   const int maxn = 1000010;   long long p[maxn], q[maxn];   int main() {     int i, n;     long long nAns = 0;     cin >> n;     n /= 2;     p[1] = 2;     q[1] = 1;     for (i = 2; i <= n; i++) {       p[i] = p[i - 1] * 2 % mod;       q[i] = q[i - 1] * (p[i] - 3) % mod;       nAns = (nAns + q[i] * 4) % mod;     }     cout << (2 * nAns * nAns % mod + nAns * 8 % mod + 10) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 7;   int main(int argc, char *argv[]) {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n, k;     std::set<std::pair<int, int> > t[maxn], s;     std::cin >> n >> k;     int u, v, w;     int ans = 0;     for (int i = 0; i < n - 1; i++) {       std::cin >> u >> v >> w;       t[u].insert(std::make_pair(v, w));       t[v].insert(std::make_pair(u, w));     }     for (int i = 1; i <= n; i++) {       if (t[i].size() == 1) {         s.insert(std::make_pair((*t[i].begin()).second, i));       }     }     while (n > k || s.size() > 2) {       auto i = *s.begin();       s.erase(i);       int cur = i.second;       ans = i.first;       n--;       int nxt = (*t[cur].begin()).first;       t[nxt].erase(t[nxt].lower_bound(std::make_pair(cur, 0)));       if (t[nxt].size() == 1) {         s.insert(std::make_pair((*t[nxt].begin()).second + ans, nxt));       }     }     std::cout << ans << std::endl;   }