#include <bits/stdc++.h>
using namespace std;
const long long N = 400005;
long long a[N], b[N];
long long frm[N], to[N], wei[N];
long long fa[N], fwei[N];
vector<long long> nei[N];
vector<long long> cyc;
bool incyc[N];
inline long long other(long long now, long long e) {
  return frm[e] ^ to[e] ^ now;
}
bool findcyc(long long now, long long lst, long long frm = -1,
             long long Wei = 0) {
  if (~fa[now]) {
    return 1;
  }
  fa[now] = lst;
  fwei[now] = Wei;
  for (long long i : nei[now]) {
    if (frm != i && findcyc(other(now, i), now, i, wei[i]) && !cyc.size()) {
      long long to = other(now, i), Now = now;
      while (Now != to) {
        b[cyc.size()] = fwei[Now];
        cyc.push_back(Now);
        Now = fa[Now];
      }
      b[cyc.size()] = wei[i];
      cyc.push_back(to);
      for (long long j : cyc) {
        incyc[j] = 1;
      }
    }
  }
  return 0;
}
long long root[N], dep[N], dp[N];
long long sz[N];
void dfsdown(long long now, long long lst) {
  sz[now] = 1;
  for (long long i : nei[now]) {
    if (!incyc[other(now, i)] && lst != other(now, i)) {
      long long to = other(now, i), w = wei[i];
      dep[to] = dep[now] + w;
      root[to] = root[now];
      dfsdown(to, now);
      sz[now] += sz[to];
      dp[now] += sz[to] * w + dp[to];
    }
  }
}
long long ans[N];
void dfsup(long long now, long long lst, long long val = 0) {
  long long n = sz[root[now]], sum = 0;
  ans[now] += val;
  ans[now] += dp[now];
  for (long long i : nei[now]) {
    if (!incyc[other(now, i)] && lst != other(now, i)) {
      long long to = other(now, i), w = wei[i];
      dfsup(to, now, val + dp[now] - dp[to] - w * sz[to] + w * (n - sz[to]));
    }
  }
}
long long hdres[N], rescyc[N], cnt[N], ps[N];
void Handle(long long n, long long add = 0) {
  long long sum = a[n];
  long long m = 0;
  for (long long i = 0; i < 2 * n; i++) {
    ps[i + 1] = ps[i] + (cnt[i] - (i != 0 ? cnt[i - 1] : 0)) * a[i];
  }
  for (long long l = 0; l < n; l++) {
    long long r = l + n;
    while (a[r] - a[m] >= a[m] - a[l] + add) {
      m++;
    }
    hdres[l] = ps[m] - ps[l + 1] - a[l] * ((m != 0 ? cnt[m - 1] : 0) - cnt[l]);
  }
}
void getrescyc() {
  long long n = cyc.size();
  for (long long i = 1; i <= 2 * n; i++) {
    a[i] = a[i - 1] + b[(i - 1) % n];
  }
  for (long long i = 0; i < 2 * n; i++) {
    cnt[i] = sz[cyc[i % n]];
    if (i) {
      cnt[i] += cnt[i - 1];
    }
  }
  Handle(n);
  for (long long i = 0; i < n; i++) {
    rescyc[cyc[i]] += hdres[i];
  }
  for (long long i = 0; i <= 2 * n; i++) {
    a[i] = a[2 * n] - a[i];
  }
  reverse(a, a + 2 * n);
  for (long long i = 0; i < 2 * n; i++) {
    cnt[i] = sz[cyc[n - (i % n) - 1]];
    if (i) {
      cnt[i] += cnt[i - 1];
    }
  }
  memset(hdres, 0, sizeof(hdres));
  Handle(n, 1);
  reverse(hdres, hdres + n);
  for (long long i = 0; i < n; i++) {
    rescyc[cyc[i]] += hdres[i];
  }
}
long long sumdep[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(fa, -1, sizeof(fa));
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> frm[i] >> to[i] >> wei[i];
    frm[i]--;
    to[i]--;
    nei[frm[i]].push_back(i);
    nei[to[i]].push_back(i);
  }
  findcyc(0, 0);
  for (long long i : cyc) {
    root[i] = i;
    dfsdown(i, i);
    dfsup(i, i);
  }
  long long sumall = 0;
  for (long long i = 0; i < n; i++) {
    sumdep[root[i]] += dep[i];
    sumall += dep[i];
  }
  for (long long i = 0; i < n; i++) {
    ans[i] += sumall - sumdep[root[i]];
    ans[i] += dep[i] * (n - sz[root[i]]);
  }
  getrescyc();
  for (long long i = 0; i < n; i++) {
    ans[i] += rescyc[root[i]];
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
