#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, sum = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * f;
}
const int MAXN = 200010;
struct edge {
  int next, to, val;
};
edge e[MAXN * 2];
int head[MAXN], cnt = 1;
void addedge(int u, int v, int w) {
  e[++cnt].next = head[u];
  e[cnt].to = v;
  e[cnt].val = w;
  head[u] = cnt;
}
bool in_circle[MAXN], visit[MAXN];
bool Found;
int from[MAXN];
vector<int> cir;
void dfs_cl(int x, int fa) {
  visit[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    if (visit[v]) {
      int tmp = x;
      while (tmp != v) {
        cir.push_back(tmp);
        in_circle[tmp] = 1;
        tmp = from[tmp];
      }
      Found = 1;
      in_circle[v] = 1;
      cir.push_back(v);
      continue;
    }
    from[v] = x;
    dfs_cl(v, x);
    if (Found) return;
  }
}
int sz[MAXN], fa[MAXN], root[MAXN];
long long f[MAXN], dis[MAXN];
void dfs(int x, int rt) {
  sz[x]++;
  root[x] = rt;
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (in_circle[v] || fa[v]) continue;
    fa[v] = x;
    dis[v] = dis[x] + e[i].val;
    dfs(v, rt);
    sz[x] += sz[v];
    f[x] += f[v] + sz[v] * e[i].val;
  }
}
long long ans[MAXN];
int n;
void dfs2(int x, int dist, int size) {
  visit[x] = 1;
  ans[x] += dist + f[x] + dis[x] * (n - sz[root[x]]);
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (visit[v] || in_circle[v]) continue;
    int szv = size + sz[x] - sz[v];
    int disv = dist + e[i].val * (szv - sz[v]) + f[x] - f[v];
    dfs2(v, disv, szv);
  }
}
long long cst[MAXN * 3], Ans[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (int i = 1; i <= n; i++)
    if (!Found) dfs_cl(i, -1);
  int num = cir.size();
  for (int i = 0; i < num; i++) dfs(cir[i], cir[i]);
  memset(visit, 0, sizeof(visit));
  for (int i = 0; i < num; i++) dfs2(cir[i], 0, 0), cir.push_back(cir[i]);
  for (int i = 0; i < num; i++) cir.push_back(cir[i]);
  for (int i = 0; i < num; i++) {
    for (int j = head[cir[i + 1]]; j; j = e[j].next) {
      int v = e[j].to;
      if (v == cir[i])
        cst[i + num + num + 1] = cst[i + num + 1] = cst[i + 1] = e[j].val;
    }
  }
  for (int i = 1; i < 3 * num; i++) cst[i] += cst[i - 1];
  long long anss = 0;
  for (int i = 1; i < num; i++) anss += (cst[num] - cst[i]) * sz[cir[i]];
  int j = num + 1, ncnt = sz[cir[num]];
  long long tot = cst[num];
  long long all = 0;
  for (int i = 0; i < num; i++) all += ans[cir[i]];
  for (int i = num; i < 2 * num; i++) {
    while (cst[j] - cst[i] <= tot / 2) {
      ncnt += sz[cir[j]];
      anss += (2 * (cst[j] - cst[i]) - tot) * sz[cir[j]];
      j++;
    }
    Ans[cir[i]] = anss;
    ncnt -= sz[cir[i]];
    anss += (n - ncnt * 2) * (cst[i + 1] - cst[i]);
  }
  for (int i = 1; i <= n; i++)
    printf("%I64d ", Ans[root[i]] + ans[i] + all - ans[root[i]]);
  return 0;
}
