#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:836777216")
using namespace std;
vector<vector<pair<int, int> > > g;
vector<pair<int, int> > cycle;
vector<pair<int, int> > tmp;
bool used[200005];
int cnt[200005];
long long dp[200005];
long long ans[200005];
long long sum_cycle = 0;
long long left_sum = 0;
long long right_sum = 0;
long long total_left = 0;
long long total_right = 0;
int cur_tree = 0;
int cnt_right;
int n;
void find_cycle(int v, int par = -1, int last = 0) {
  used[v] = 1;
  for (int(i) = 0; (i) < ((int)(g[v]).size()); (i)++) {
    int u = g[v][i].first;
    int p = g[v][i].second;
    if (u == par) {
      continue;
    }
    if (used[u]) {
      if (!(int)(cycle).size()) {
        cycle.push_back(make_pair(v, p));
        int idx = (int)(tmp).size() - 1;
        do {
          cycle.push_back(tmp[idx]);
        } while (tmp[idx--].first != u);
      }
    } else {
      tmp.push_back(make_pair(v, p));
      find_cycle(u, v, p);
      tmp.pop_back();
    }
  }
}
void dfs1(int v) {
  cnt[v] = 1;
  used[v] = 1;
  dp[v] = 0;
  for (int(i) = 0; (i) < ((int)(g[v]).size()); (i)++) {
    int u = g[v][i].first;
    int p = g[v][i].second;
    if (!used[u]) {
      dfs1(u);
      cnt[v] += cnt[u];
      dp[v] += dp[u] + (long long)p * cnt[u];
    }
  }
}
void dfs2(int v, long long depth = 0) {
  used[v] = 1;
  ans[v] = dp[v];
  ans[v] += depth * (n - cur_tree);
  ans[v] += total_left + total_right;
  ans[v] += sum_cycle;
  for (int(i) = 0; (i) < ((int)(g[v]).size()); (i)++) {
    int u = g[v][i].first;
    int p = g[v][i].second;
    if (!used[u]) {
      dp[u] =
          dp[v] - (long long)cnt[u] * p + (long long)(cur_tree - cnt[u]) * p;
      dfs2(u, depth + p);
    }
  }
}
int main(void) {
  scanf("%d", &n);
  g.resize(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  memset((used), (0), sizeof((used)));
  find_cycle(0);
  reverse((cycle).begin(), (cycle).end());
  int l = (int)(cycle).size();
  memset((used), (0), sizeof((used)));
  for (int(i) = 0; (i) < (l); (i)++) {
    used[cycle[i].first] = 1;
  }
  for (int(i) = 0; (i) < (l); (i)++) {
    dfs1(cycle[i].first);
    sum_cycle += dp[cycle[i].first];
    right_sum += cycle[i].second;
  }
  memset((used), (0), sizeof((used)));
  for (int(i) = 0; (i) < (l); (i)++) {
    used[cycle[i].first] = 1;
  }
  int p2 = 0;
  long long tmp_sum = right_sum;
  for (int(i) = 0; (i) < (l); (i)++) {
    total_right += tmp_sum * cnt[cycle[i].first];
    tmp_sum -= cycle[i].second;
  }
  cnt_right = n;
  for (int(p1) = 0; (p1) < (l); (p1)++) {
    while (left_sum < right_sum) {
      total_left += left_sum * cnt[cycle[p2].first];
      left_sum += (long long)cycle[p2].second;
      total_right -= right_sum * cnt[cycle[p2].first];
      right_sum -= (long long)cycle[p2].second;
      cnt_right -= cnt[cycle[p2].first];
      p2 = (p2 + 1) % l;
    }
    sum_cycle -= dp[cycle[p1].first];
    cur_tree = cnt[cycle[p1].first];
    dfs2(cycle[p1].first);
    sum_cycle += dp[cycle[p1].first];
    total_left -= (n - cnt_right - cnt[cycle[p1].first]) * cycle[p1].second;
    cnt_right += cnt[cycle[p1].first];
    total_right += cnt_right * cycle[p1].second;
    right_sum += cycle[p1].second;
    left_sum -= cycle[p1].second;
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    printf("%lld%c", ans[i], (i == n - 1 ? '\n' : ' '));
  }
  return 0;
}
