#include <bits/stdc++.h>
using namespace std;
int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); }
const int maxn = 200010;
int n, m, pos, tal, sav;
int d[maxn], g[maxn], p[maxn], s[maxn], sl[maxn], sr[maxn], cir[maxn],
    dis[maxn], ins[maxn], pre[maxn], vis[maxn], sum[maxn];
long long f[maxn], h[maxn], ls[maxn], rs[maxn];
int len[maxn * 2], vec[maxn * 2], nxt[maxn * 2];
int sc(int x) { return (x - 1 + m) % m; }
int ps(int x) { return (x + 1) % m; }
void Dfs(int t) {
  vis[t] = 1;
  for (int i = g[t]; i != -1; i = nxt[i])
    if (!vis[vec[i]]) {
      p[vec[i]] = t;
      pre[vec[i]] = len[i];
      Dfs(vec[i]);
    } else if (vec[i] != p[t]) {
      if (pos == -1) {
        pos = t;
        tal = vec[i];
        sav = len[i];
      }
    }
}
void Dp(int t) {
  s[t] = 1;
  for (int i = g[t]; i != -1; i = nxt[i])
    if (vec[i] != p[t] && !ins[vec[i]]) {
      p[vec[i]] = t;
      Dp(vec[i]);
      s[t] += s[vec[i]];
      f[t] += (long long)s[vec[i]] * len[i] + f[vec[i]];
    }
}
void Calc(int t) {
  for (int i = g[t]; i != -1; i = nxt[i])
    if (vec[i] != p[t] && !ins[vec[i]]) {
      p[vec[i]] = t;
      h[vec[i]] = h[t] + f[t] - (long long)s[vec[i]] * len[i] - f[vec[i]] +
                  (long long)(n - s[vec[i]]) * len[i];
      Calc(vec[i]);
    }
}
int dist(int u, int v) {
  if (u < v)
    return sum[v] - sum[u];
  else
    return sum[m - 1] - sum[u] + dis[m - 1] + sum[v];
}
int dist_(int u, int v) {
  if (u <= v)
    return sum[v] - sum[u];
  else
    return sum[m - 1] - sum[u] + dis[m - 1] + sum[v];
}
int main() {
  cin >> n;
  memset(g, -1, sizeof(g));
  long long tot = 0;
  for (int i = 0; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    len[tot] = w, vec[tot] = v, nxt[tot] = g[u], g[u] = tot++;
    len[tot] = w, vec[tot] = u, nxt[tot] = g[v], g[v] = tot++;
  }
  memset(vis, 0, sizeof(vis));
  p[0] = -1;
  pos = -1;
  Dfs(0);
  memset(ins, 0, sizeof(ins));
  m = 0;
  while (pos != tal) {
    ins[pos] = 1;
    cir[m] = pos;
    dis[m++] = pre[pos];
    pos = p[pos];
  }
  ins[pos] = 1;
  cir[m] = pos;
  dis[m++] = sav;
  sum[0] = 0;
  for (int i = 1; i < m; i++) sum[i] = sum[i - 1] + dis[i - 1];
  memset(p, -1, sizeof(p));
  for (int i = 0; i < n; i++)
    if (ins[i]) Dp(i);
  tot = 0;
  for (int i = 0; i < m; i++) tot += f[cir[i]];
  for (d[0] = 0; dist(0, ps(d[0])) <= dist_(ps(d[0]), 0); d[0] = ps(d[0]))
    ;
  for (int i = 1; i < m; i++) {
    d[i] = d[i - 1] == i - 1 ? i : d[i - 1];
    for (; dist(i, ps(d[i])) <= dist_(ps(d[i]), i); d[i] = ps(d[i]))
      ;
  }
  sl[0] = s[cir[0]];
  for (int i = 1; i < m; i++) sl[i] = sl[i - 1] + s[cir[i]];
  sr[m - 1] = s[cir[m - 1]];
  for (int i = m - 2; i >= 0; i--) sr[i] = sr[i + 1] + s[cir[i]];
  ls[0] = 0;
  for (int i = 1; i < m; i++) ls[i] = ls[i - 1] + (long long)s[cir[i]] * sum[i];
  rs[m - 1] = 0;
  for (int i = m - 2; i >= 0; i--)
    rs[i] = rs[i + 1] + (long long)s[cir[i]] * (sum[m - 1] - sum[i]);
  for (int i = 0; i < m; i++) {
    long long res = tot - f[cir[i]];
    if (i != d[i]) {
      if (i < d[i])
        res += ls[d[i]] - ls[i] - (long long)(sl[d[i]] - sl[i]) * sum[i];
      else {
        res += ls[m - 1] - ls[i] - (long long)(sl[m - 1] - sl[i]) * sum[i];
        res +=
            ls[d[i]] + (long long)sl[d[i]] * (dis[m - 1] + sum[m - 1] - sum[i]);
      }
    }
    int k = ps(d[i]);
    if (i != k) {
      if (k < i)
        res +=
            rs[k] - rs[i] - (long long)(sr[k] - sr[i]) * (sum[m - 1] - sum[i]);
      else {
        res +=
            rs[0] - rs[i] - (long long)(sr[0] - sr[i]) * (sum[m - 1] - sum[i]);
        res += rs[k] + (long long)sr[k] * (dis[m - 1] + sum[i]);
      }
    }
    h[cir[i]] = res;
  }
  memset(p, -1, sizeof(p));
  for (int i = 0; i < n; i++)
    if (ins[i]) Calc(i);
  for (int i = 0; i < n; i++) {
    cout << f[i] + h[i];
    if (i < n - 1)
      cout << ' ';
    else
      cout << endl;
  }
  return 0;
}
