#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
struct edge {
  int a, b, t;
  edge() {}
  edge(int a, int b, int t) : a(a), b(b), t(t) {}
  inline int to(int x) { return x == a ? b : a; }
} e[maxn];
vector<int> g[maxn], st, tmp;
long long predis[maxm], bckdis[maxm], presz[maxm], bcksz[maxm];
long long preans[maxn], bckans[maxm];
int dfn[maxn], low[maxn], Time;
bool vis[maxn], inc[maxn];
void tarjan(int x, int fa) {
  dfn[x] = low[x] = ++Time;
  st.push_back(x);
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int to = e[g[x][i]].to(x);
    if (to == fa) continue;
    if (!vis[to]) {
      tarjan(to, x);
      low[x] = min(low[x], low[to]);
    } else {
      low[x] = min(low[x], dfn[to]);
    }
  }
  if (low[x] == dfn[x]) {
    tmp.clear();
    int cnt = 1;
    while (st.back() != x) {
      tmp.push_back(st.back());
      st.pop_back();
      cnt++;
    }
    tmp.push_back(st.back());
    st.pop_back();
    if (cnt > 1) {
      for (int i = 0; i < tmp.size(); i++) inc[tmp[i]] = 1;
    }
  }
}
long long sz[maxn], insidedist[maxn];
void getlink(int x, int fa) {
  sz[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int to = e[g[x][i]].to(x);
    if (to == fa || inc[to]) continue;
    getlink(to, x);
    sz[x] += sz[to];
    insidedist[x] += sz[to] * e[g[x][i]].t + insidedist[to];
  }
}
long long cor[maxn], ed[maxn], cm, allsum;
void formcycle(int x, int p) {
  if (p > cm) return;
  vis[x] = 1;
  cor[p] = x;
  for (int i = 0; i < g[x].size(); i++) {
    int to = e[g[x][i]].to(x);
    if (inc[to] && !vis[to]) {
      formcycle(to, p + 1);
      ed[p] = e[g[x][i]].t, allsum += ed[p];
      break;
    } else if (p == cm && to == cor[1]) {
      ed[p] = e[g[x][i]].t, allsum += ed[p];
      break;
    }
  }
}
int n;
inline long long getlsum(int fr, int to) {
  if (to < fr) to += cm;
  return predis[to - 1] - predis[fr - 1];
}
inline long long getrsum(int fr, int to) { return allsum - getlsum(to, fr); }
inline long long getlsz(int fr, int to) {
  if (to < fr) to += cm;
  return presz[to] - presz[fr - 1];
}
long long ans[maxn];
void makeans(int x, long long sum, int fa) {
  ans[x] = sum;
  for (int i = 0; i < g[x].size(); i++) {
    int to = e[g[x][i]].to(x);
    if (to == fa || inc[to]) continue;
    int cst = e[g[x][i]].t;
    makeans(to, sum - cst * (2 * sz[to] - n), x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].t);
    g[e[i].a].push_back(i);
    g[e[i].b].push_back(i);
  }
  tarjan(1, 0);
  for (int i = 1; i <= n; i++)
    if (inc[i]) {
      getlink(i, i);
      cm++;
    }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (inc[i]) {
      formcycle(i, 1);
      break;
    }
  for (int i = 1; i <= cm; i++)
    predis[i] = predis[i - 1] + ed[i], presz[i] = presz[i - 1] + sz[cor[i]];
  for (int i = cm + 1; i <= cm + cm; i++)
    predis[i] = predis[i - 1] + ed[i - cm],
    presz[i] = presz[i - 1] + sz[cor[i - cm]];
  int l = cm, r = 1, lft = 2;
  long long sum = 0;
  for (int i = 2; i <= cm; i++)
    sum += sz[cor[i]] * getlsum(i, 1) + insidedist[cor[i]];
  sum += insidedist[cor[1]];
  for (int i = 1; i <= cm; i++) {
    while (lft != i && getlsum(lft, i) > getrsum(i, lft)) {
      sum -= sz[cor[lft]] * getlsum(lft, i);
      sum += sz[cor[lft]] * getrsum(i, lft);
      lft++;
      if (lft > cm) lft -= cm;
    }
    makeans(cor[i], sum, cor[i]);
    if (i != cm && lft == i + 1) {
      sum -= sz[cor[lft]] * getlsum(lft, i);
      sum += sz[cor[lft]] * getrsum(i, lft);
      lft++;
      if (lft > cm) lft -= cm;
    }
    sum += ed[i] * (2 * getlsz(lft, i) - (n));
  }
  for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
  return 0;
  for (int i = 1; i <= n; i++) {
    presz[i] = presz[i - 1] + sz[cor[i]];
    predis[i + 1] = predis[i] + presz[i] * ed[i];
  }
  for (int i = n + 1; i <= n + n - 1; i++) {
    presz[i] = presz[i - 1] + sz[cor[i - n]];
    predis[i + 1] = predis[i] + presz[i] * ed[i - n];
  }
  preans[n] = predis[n + 1];
  for (int i = 1; i < n; i++)
    preans[i] = predis[n + i] - predis[i] - i * allsum;
  for (int i = 1; i <= n; i++) {
    bcksz[i] = bcksz[i - 1] + sz[cor[n + 1 - i]];
    bckdis[i + 1] = bckdis[i - 1] + bcksz[i] * (i == n ? ed[n] : ed[n - i]);
  }
  for (int i = n + 1; i <= n + n - 1; i++) {
    bcksz[i] = bcksz[i - 1] + sz[cor[n + 1 - i + n]];
    bckdis[i + 1] = bckdis[i] + bcksz[i] * (i == n + n ? ed[n] : ed[n - i + n]);
  }
  bckans[1] = bckdis[n + 1];
  for (int i = 1; i < n; i++)
    bckans[n + 1 - i] = bckdis[n + i] - bckdis[i] - i * allsum;
}
