func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, k, u, v, w;   unordered_map<long long, vector<long long>> m;   struct Key {     long long N, p;     bool operator==(const Key& other) const {       return (N == other.N && p == other.p);     }   };   struct KeyHasher {     size_t operator()(const Key& k) const { return k.N * 59 + k.p * 61; }   };   set<pair<long long, long long>, greater<pair<long long, long long>>> sp[100010];   unordered_map<Key, long long, KeyHasher> done, wt, val;   long long dfs(long long i, vector<bool>& vis) {     vis[i] = 1;     long long mx = 0;     for (auto it : m[i]) {       if (vis[it] == 0) {         long long v = dfs(it, vis);         long long jk = val[{it, i}] = v + wt[{it, i}];         sp[i].insert({jk, it});         mx = max(mx, val[{it, i}]);       }     }     return mx;   }   void dfs2(long long i, vector<bool>& vis) {     vis[i] = 1;     for (auto it : m[i]) {       if (vis[it] == 0) {         long long mx = 0;         for (auto pt : sp[i]) {           if (it != pt.second) {             mx = pt.first;             break;           }         }         long long jk = val[{i, it}] = mx + wt[{i, it}];         sp[it].insert({jk, i});         dfs2(it, vis);       }     }   }   int main() {     cin >> n >> k;     for (long long i = 1; i < n; i++) {       cin >> u >> v >> w;       m[u].push_back(v);       m[v].push_back(u);       wt[{u, v}] = wt[{v, u}] = w;     }     vector<bool> vis(n + 1, 0);     vector<bool> vis2(n + 1, 0);     dfs(1, vis);     dfs2(1, vis2);     long long mn = LLONG_MAX, ind;     for (auto it : m) {       long long mx = 0;       for (auto i : it.second) mx = max(mx, val[{i, it.first}]);       if (mn > mx) {         mn = mx;         ind = it.first;       }     }     k--;     vector<long long> v;     v.push_back(ind);     long long s = ind, e = ind;     while (k) {       long long mx = 0, in, f = 0, first = 0;       for (auto it : m[s]) {         if (done[{it, s}] == 0) {           first = 1;           if (mx < val[{it, s}]) {             mx = val[{it, s}];             in = it;           }         }       }       if (s != e) {         for (auto it : m[e]) {           if (done[{it, e}] == 0) {             first = 1;             if (mx < val[{it, e}]) {               f = 1;               mx = val[{it, e}];               in = it;             }           }         }       }       if (first == 0) break;       if (f) {         done[{e, in}] = done[{in, e}] = 1;         e = in;       } else {         done[{s, in}] = done[{in, s}] = 1;         s = in;       }       v.push_back(in);       k--;     }     long long mx = 0;     for (auto it : v) {       for (auto i : m[it]) {         if (done[{it, i}] == 0) mx = max(mx, val[{i, it}]);       }     }     cout << mx;     return 0;   }   