#include <bits/stdc++.h>
using namespace std;
int read() {
  int a = 0, b = getchar();
  while (!isdigit(b)) b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a;
}
const int N = 2e5 + 5;
long long n, m, z, d[N * 6], w[N * 6], u[N], r1[N], r2[N], e[N], s[N * 6];
vector<int> g[N], f[N];
bool c[N], q;
void gg(int i, int l, int p) {
  int j;
  if (u[i] == z) {
    for (j = l - 1; d[j] != i; j--) c[d[j]] = true;
    for (int k = j; k < l; k++) d[k - j] = d[k];
    m = l - j, c[i] = q = true;
    return;
  }
  u[i] = z, d[l] = i;
  for (j = 0; j < g[i].size(); j++) {
    int k = g[i][j];
    if (k != p) gg(k, l + 1, i);
    if (q) break;
  }
}
void dfs(int i, int p) {
  int j, k;
  r1[i] = 0;
  e[i] = 1;
  for (j = 0; j < g[i].size(); j++) {
    k = g[i][j];
    if (k != p and !c[k]) {
      dfs(k, i);
      e[i] += e[k];
      r1[i] += r1[k] + e[k] * f[i][j];
    }
  }
}
void gao(int i, int p, long long s, long long t) {
  int j, k;
  r2[i] = s;
  for (j = 0; j < g[i].size(); j++) {
    k = g[i][j];
    if (k != p and !c[k])
      gao(k, i, s + r1[i] - r1[k] + (t + e[i] - 2 * e[k]) * f[i][j],
          t + e[i] - e[k]);
  }
}
int main() {
  n = read();
  for (int i = 0; i < n; i++) {
    int x = read(), y = read(), z = read();
    g[x].push_back(y);
    f[x].push_back(z);
    g[y].push_back(x);
    f[y].push_back(z);
  }
  z = 1;
  gg(1, 0, 0);
  for (int i = 0; i < m; i++) {
    dfs(d[i], 0);
    d[m + i] = d[i];
    d[m + m + i] = d[i];
    for (int x = 0; x < g[d[i]].size(); x++)
      if (g[d[i]][x] == d[i + 1]) {
        w[i] = f[d[i]][x];
        w[m + i] = w[i];
        w[m + m + i] = w[i];
        break;
      }
    s[i + 1] = s[i] + w[i];
  }
  for (int i = m; i < 3 * m; i++) s[i + 1] = s[i] + w[i];
  long long x = 1, y = m, ab = 0, l = 0, r = 0;
  for (int i = 1; i < m; i++) {
    ab += (s[m] - s[i]) * e[d[i]] + r1[d[i]];
    l += e[d[i]];
  }
  for (int i = m; i < m + m; i++) {
    while (x < i and (s[i] - s[x] > s[y + 1] - s[i] or y < i)) {
      ab += (s[y + 1] - s[i] - s[i] + s[x]) * e[d[x]];
      l -= e[d[x]];
      r += e[d[y + 1]];
      x++, y++;
    }
    gao(d[i], 0, ab, l + r);
    l += e[d[i]];
    ab += w[i] * (l - r) + r1[d[i]] - r1[d[i + 1]];
    r -= e[d[i + 1]];
  }
  for (int i = 1; i <= n; i++) printf("%lld ", r1[i] + r2[i]);
  return 0;
}
