func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 212345, MAXL = 20, INF = 1123456789;   vector<int> grafo[MAXN], peso[MAXN];   int dp[MAXN][MAXL], mx[MAXN][MAXL], dist[MAXN], prof[MAXN];   long long int pmst;   pair<int, pair<int, int> > ar[MAXN];   int lca(int a, int b) {     int resp = 0;     if (prof[a] < prof[b]) swap(a, b);     int d = prof[a] - prof[b];     for (int i = MAXL - 1; i >= 0; i--) {       if (d & (1 << i)) {         resp = max(resp, mx[a][i]);         a = dp[a][i];       }     }     if (a == b) return resp;     for (int i = MAXL - 1; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         resp = max(resp, max(mx[a][i], mx[b][i]));         a = dp[a][i];         b = dp[b][i];       }     }     resp = max(resp, max(mx[a][0], mx[b][0]));     return resp;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, p;       scanf( %d %d %d , &a, &b, &p);       a--;       b--;       grafo[a].push_back(b);       grafo[b].push_back(a);       peso[a].push_back(p);       peso[b].push_back(p);       ar[i] = make_pair(p, make_pair(a, b));     }     set<pair<int, int> > s;     dist[0] = 0;     s.insert(make_pair(0, 0));     for (int i = 1; i < n; i++) {       dist[i] = INF;       s.insert(make_pair(INF, i));     }     dp[0][0] = 0;     prof[0] = 0;     while (!s.empty()) {       int cur = (*s.begin()).second;       s.erase(s.begin());       pmst += dist[cur];       dist[cur] = 0;       for (int i = 0; i < grafo[cur].size(); i++) {         int viz = grafo[cur][i], p = peso[cur][i];         if (dist[viz] > p) {           s.erase(make_pair(dist[viz], viz));           dist[viz] = p;           s.insert(make_pair(dist[viz], viz));           dp[viz][0] = cur;           mx[viz][0] = p;           prof[viz] = prof[cur] + 1;         }       }     }     for (int j = 1; j < MAXL; j++) {       for (int i = 0; i < n; i++) {         dp[i][j] = dp[dp[i][j - 1]][j - 1];         mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);       }     }     for (int i = 0; i < m; i++) {       printf( %lld n ,              pmst - lca(ar[i].second.first, ar[i].second.second) + ar[i].first);     }     return 0;   }   