#include <bits/stdc++.h>
using namespace std;
const int MAX = 200020;
int head[MAX], nxt[MAX << 1], to[MAX << 1], cost[MAX << 1], ent;
int sta[MAX], sta2[MAX], cnt1, cnt2;
int cir[MAX], co[MAX], cnt3, cnt4;
int deep[MAX];
vector<int> cirV[MAX];
bool in[MAX];
int vist[MAX], num[MAX];
long long dist[MAX];
int n;
void dfs(int v, int p) {
  vist[v] = 1;
  sta[cnt1++] = v;
  for (int i = head[v]; ~i; i = nxt[i]) {
    int u = to[i], cc = cost[i];
    if (vist[u] == 0) {
      sta2[cnt2++] = cc;
      dfs(u, v);
    } else if (vist[u] == 1 && u != p) {
      int j;
      for (j = 0; j < cnt1; j++)
        if (sta[j] == u) break;
      for (int k = j; k < cnt1; k++) cir[k - j] = sta[k], in[sta[k]] = 1;
      cnt3 = cnt1 - j;
      for (int k = j; k < cnt2; k++) co[k - j] = sta2[k];
      cnt4 = cnt2 - j;
      co[cnt4++] = cc;
    }
  }
  cnt1--;
  cnt2--;
  vist[v] = 2;
}
void dfs2(int v, int de, vector<int> &ve) {
  vist[v] = 1;
  deep[v] = de;
  ve.push_back(v);
  num[v] = 1, dist[v] = 0;
  for (int i = head[v]; ~i; i = nxt[i]) {
    int u = to[i], cc = cost[i];
    if (!in[u] && vist[u] == 0) {
      dfs2(u, de + cc, ve);
      num[v] += num[u];
      dist[v] += dist[u] + num[u] * cc;
    }
  }
}
int total;
void dfs3(int v) {
  vist[v] = 1;
  for (int i = head[v]; ~i; i = nxt[i]) {
    int u = to[i], cc = cost[i];
    if (!in[u] && vist[u] == 0) {
      dist[u] = dist[v] + total * cc - 2 * num[u] * cc;
      dfs3(u);
    }
  }
}
inline void add(int a, int b, int c) {
  nxt[ent] = head[a], to[ent] = b, cost[ent] = c, head[a] = ent++;
  nxt[ent] = head[b], to[ent] = a, cost[ent] = c, head[b] = ent++;
}
int debug = 0;
int main() {
  scanf("%d", &n);
  ent = 0;
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= n; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    add(a, b, c);
  }
  memset(vist, 0, sizeof(vist));
  cnt1 = cnt2 = cnt3 = cnt4 = 0;
  memset(in, 0, sizeof(in));
  dfs(1, -1);
  memset(vist, 0, sizeof(vist));
  for (int i = 0; i < cnt3; i++) {
    dfs2(cir[i], 0, cirV[i]);
  }
  memset(vist, 0, sizeof(vist));
  for (int i = 0; i < cnt3; i++) {
    total = num[cir[i]];
    dfs3(cir[i]);
  }
  long long d2 = 0, r = 0, l = 0, lid = 0, d1 = 0, tdist = 0, c1 = num[cir[0]],
            tval = 0, tt;
  for (int j = cnt3 - 1; j >= 1; j--) {
    d2 += co[j];
    r += d2 * num[cir[j]];
    tval += dist[cir[j]];
  }
  tval += dist[cir[0]];
  tdist = d2 + co[0];
  for (int i = 0; i <= cnt3 - 1; ++i) {
    tt = tval - dist[cir[i]];
    while (d1 + co[lid] <= tdist / 2) {
      d1 += co[lid];
      lid = (lid + 1) % cnt3;
      l += d1 * num[cir[lid]];
      c1 += num[cir[lid]];
      r -= (tdist - d1) * num[cir[lid]];
    }
    for (int j = 0; j < cirV[i].size(); j++) {
      int u = cirV[i][j];
      dist[u] += l + r + tt + (long long)deep[u] * (n - num[cir[i]]);
    }
    if (lid != i) {
      r += (n - c1 + num[cir[i]]) * co[i];
      l -= (c1 - num[cir[i]]) * co[i];
      c1 -= num[cir[i]], d1 -= co[i];
    } else {
      tt = (lid + 1) % cnt3;
      r -= (tdist - co[lid]) * num[cir[tt]];
      r += (n - num[cir[tt]]) * co[lid];
      lid = (i + 1) % cnt3;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", dist[i]);
  printf("\n");
  return 0;
}
