#include <bits/stdc++.h>
using namespace std;
long long siz[1001000], vis[1001000], dis_to_root[1001000], g[1001000], i, n,
    size, st1[1001000], loop[1001000], len[1001000];
long long top, root[1001000], st[1001000], l_sum, r_sum, l_siz, r_siz,
    be_loop[1001000], fa[1001000], sum[1001000];
long long ans[1001000], sum_len, j, o, p, w, loop_size, now, tot_len, tmp1;
struct node {
  long long to, next, v;
} e[1001000];
void add(long long o, long long p, long long q) {
  e[++size].to = p, e[size].next = g[o];
  g[o] = size, e[size].v = q;
}
long long find_loop(long long x) {
  if (vis[x] != 0) {
    tmp1 = top;
    return vis[x];
  }
  st[++top] = x;
  vis[x] = top;
  for (long long k = g[x]; k; k = e[k].next) {
    long long y = e[k].to;
    if (y != fa[x]) {
      fa[y] = x;
      long long t = find_loop(y);
      if (t) {
        st1[top--] = e[k].v;
        return t;
      }
    }
  }
  top--;
  return 0;
}
void calc(long long x) {
  siz[x]++;
  root[x] = loop[i];
  for (long long k = g[x]; k; k = e[k].next) {
    long long y = e[k].to;
    if (be_loop[y] == 0 && y != fa[x]) {
      fa[y] = x;
      dis_to_root[y] = dis_to_root[x] + e[k].v;
      sum[loop[i]] += dis_to_root[y];
      calc(y);
      siz[x] += siz[y];
    }
  }
}
void solve(long long x) {
  for (long long k = g[x]; k; k = e[k].next) {
    long long y = e[k].to;
    if (y != fa[x] && be_loop[y] == 0) {
      long long tmp = (siz[root[x]] - 2 * siz[y]) * e[k].v;
      now += tmp;
      sum[y] = now;
      solve(y);
      now -= tmp;
    }
  }
}
void dfs(long long x) {
  ans[x] = l_sum + r_sum + sum[x] + dis_to_root[x] * (n - siz[loop[i]]);
  for (long long k = g[x]; k; k = e[k].next) {
    long long y = e[k].to;
    if (be_loop[y] == 0 && y != fa[x]) {
      dfs(y);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d %d", &o, &p, &w);
    add(o, p, w);
    add(p, o, w);
  }
  long long tmp = find_loop(1);
  for (i = tmp; i <= tmp1; i++)
    loop[++loop_size] = st[i], len[loop_size] = st1[i], be_loop[st[i]] = 1,
    tot_len += st1[i];
  for (i = 1; i <= loop_size; i++) {
    calc(loop[i]);
    now = sum[loop[i]];
    solve(loop[i]);
  }
  j = 2;
  for (i = 2; i <= loop_size; i++) {
    l_siz += siz[loop[i]];
    l_sum += l_siz * len[i] + sum[loop[i]];
  }
  sum_len = len[1];
  for (i = 1; i <= loop_size; i++) {
    while (tot_len - sum_len > sum_len) {
      r_sum += sum_len * siz[loop[j]] + sum[loop[j]];
      l_sum -= (tot_len - sum_len) * siz[loop[j]] + sum[loop[j]];
      r_siz += siz[loop[j]];
      l_siz -= siz[loop[j]];
      sum_len += len[j];
      j++;
      if (j == loop_size + 1) j = 1;
    }
    dfs(loop[i]);
    r_sum -= len[i] * r_siz;
    r_sum -= sum[loop[i + 1]];
    l_sum += sum[loop[i]];
    l_siz += siz[loop[i]];
    l_sum += len[i] * l_siz;
    r_siz -= siz[loop[i + 1]];
    sum_len -= len[i];
  }
  for (i = 1; i <= n; i++) printf("%I64d ", ans[i]);
}
