#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 1;
long long f[N], g[N];
stack<int> cir;
vector<int> w[N], edge[N];
inline void add_edge(int x, int y, int z) {
  edge[x].push_back(y);
  w[x].push_back(z);
}
int vis[N];
int root[N], cnt, n;
int isroot[N], siz[N], sizg[N];
int flag;
void dfs(int x, int fa) {
  vis[x] = 1;
  cir.push(x);
  for (int i = 0; i < (int)edge[x].size(); ++i) {
    int y = edge[x][i];
    if (y == fa) continue;
    if (vis[y]) {
      flag = y;
      return;
    }
    dfs(y, x);
    if (flag) return;
  }
  cir.pop();
}
int belong[N], dep[N];
void qdis1(int x, int fa, int ind) {
  belong[x] = ind;
  siz[x] = 1;
  for (int i = 0; i < (int)edge[x].size(); ++i) {
    int y = edge[x][i], ew = w[x][i];
    if (y == fa || isroot[y]) continue;
    dep[y] = dep[x] + ew;
    qdis1(y, x, ind);
    siz[x] += siz[y];
    f[x] += f[y] + ew * siz[y];
  }
}
void qdis2(int x, int fa) {
  for (int i = 0; i < (int)edge[x].size(); ++i) {
    int y = edge[x][i], ew = w[x][i];
    if (y == fa || isroot[y]) continue;
    g[y] =
        g[x] + (f[x] - f[y] - ew * siz[y]) + (siz[x] - siz[y] + sizg[x]) * ew;
    sizg[y] = sizg[x] + siz[x] - siz[y];
    qdis2(y, x);
  }
}
long long nxtw[N];
long long hlen;
void qcir(int x) {
  vis[x] = 1;
  for (int i = 0; i < (int)edge[x].size(); ++i) {
    int y = edge[x][i], ew = w[x][i];
    if (y != root[(isroot[x]) % cnt + 1]) continue;
    nxtw[x] = ew;
    hlen += ew;
    if (vis[y]) break;
    qcir(y);
  }
}
long long pre[N], suf[N], sizp[N], sizs[N];
long long disp[N], diss[N];
long long lenp[N], lens[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  dfs(1, 0);
  while (!cir.empty()) {
    root[++cnt] = cir.top(), cir.pop();
    if (root[cnt] == flag) break;
  }
  for (int i = 1; i <= cnt; ++i) isroot[root[i]] = i;
  for (int i = 1; i <= cnt; ++i) {
    g[root[i]] = sizg[root[i]] = 0;
    dep[root[i]] = 0;
    qdis1(root[i], 0, i);
    qdis2(root[i], 0);
  }
  memset(vis, 0, sizeof vis);
  qcir(root[1]);
  long long sum = 0;
  for (int i = 1; i <= cnt; ++i) {
    root[cnt + i] = root[i];
    sum += f[root[i]];
  }
  for (int i = 1; i <= 2 * cnt; ++i) {
    lenp[i] = lenp[i - 1] + nxtw[root[i - 1]];
    disp[i] = disp[i - 1] + sizp[i - 1] * nxtw[root[i - 1]];
    sizp[i] = sizp[i - 1] + siz[root[i]];
  }
  for (int i = 2 * cnt; i > 0; --i) {
    lens[i] = lens[i + 1] + nxtw[root[i]];
    diss[i] = diss[i + 1] + sizs[i + 1] * nxtw[root[i]];
    sizs[i] = sizs[i + 1] + siz[root[i]];
  }
  for (int i = 1; i <= n; ++i) {
    long long res = 0;
    res = f[i] + g[i];
    int q = belong[i];
    int L = q, R = q + cnt;
    while (L < R) {
      int mid = (L + R + 1) / 2;
      if ((lenp[mid] - lenp[q]) * 2 > hlen)
        R = mid - 1;
      else
        L = mid;
    }
    res += sum - f[root[q]] + diss[q] - diss[L + 1] -
           1LL * sizs[L + 1] * (lens[q] - lens[L + 1]);
    res += disp[q + cnt] - disp[L] - 1LL * sizp[L] * (lenp[q + cnt] - lenp[L]);
    res += 1LL * dep[i] * (n - siz[root[q]]);
    printf("%lld ", res);
  }
  puts("");
  return 0;
}
