#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > g[200001];
vector<pair<int, int> > ng;
int par[200000], ra[200000];
int tin[200000], fup[200000], timer = 0;
bool incyc[200000] = {};
int cyc, clen = 0;
int sz[200000];
long long distSum[200000], ans[200000], ans2[200000];
void dsuInit() {
  for (int i = 0; i < (int)(n); ++i) par[i] = i, ra[i] = 1;
}
int dsuParent(int v) {
  if (v == par[v]) return v;
  return par[v] = dsuParent(par[v]);
}
void dsuMerge(int u, int v) {
  u = dsuParent(u);
  v = dsuParent(v);
  if (u == v) return;
  if (ra[u] < ra[v]) swap(u, v);
  par[v] = u;
  ra[u] += ra[v];
}
void dfs(int v, int p) {
  tin[v] = fup[v] = timer++;
  for (pair<int, int> to : g[v])
    if (to.first != p) {
      if (tin[to.first] == -1) {
        dfs(to.first, v);
        if (fup[to.first] <= tin[v]) {
          dsuMerge(to.first, v);
        }
        fup[v] = min(fup[v], fup[to.first]);
      } else {
        fup[v] = min(fup[v], tin[to.first]);
      }
    }
}
void dfs2(int v, int p) {
  sz[v] = 1;
  distSum[v] = 0;
  vector<pair<int, int> > *q;
  if (p == -1)
    q = &ng;
  else
    q = g + v;
  for (pair<int, int> to : *q)
    if (!incyc[to.first] && to.first != p) {
      dfs2(to.first, v);
      distSum[v] += distSum[to.first] + sz[to.first] * to.second;
      sz[v] += sz[to.first];
    }
}
void dfs3(int v, int p, int lastLen) {
  vector<pair<int, int> > *q;
  if (p == -1)
    q = &ng;
  else
    q = g + v;
  if (p != -1) {
    distSum[v] += distSum[p] - distSum[v] + lastLen * (n - 2 * sz[v]);
  }
  for (pair<int, int> to : *q)
    if (!incyc[to.first] && to.first != p) {
      dfs3(to.first, v, to.second);
    }
}
int a[400000], len[400000], pos = 0, asz[400000], ind[400000];
void dfs4(int v, int p) {
  asz[v] = 1;
  for (pair<int, int> to : g[v])
    if (!incyc[to.first] && to.first != p) {
      dfs4(to.first, v);
      asz[v] += asz[to.first];
    }
}
long long updVal;
void dfs5(int v, int p) {
  if (p != -1) {
    ans[v] += updVal;
  }
  for (pair<int, int> to : g[v])
    if (!incyc[to.first] && to.first != p) {
      dfs5(to.first, v);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) {
    int from, to, w;
    scanf("%d%d%d", &from, &to, &w), --from, --to;
    g[from].push_back(make_pair(to, w));
    g[to].push_back(make_pair(from, w));
  }
  dsuInit();
  for (int i = 0; i < (int)(n); ++i) tin[i] = -1;
  dfs(0, -1);
  for (int i = 0; i < (int)(n); ++i)
    if (dsuParent(i) != i) {
      cyc = dsuParent(i);
      break;
    }
  for (int i = 0; i < (int)(n); ++i) incyc[i] = dsuParent(i) == cyc;
  for (int i = 0; i < (int)(n); ++i)
    if (dsuParent(i) == cyc)
      for (pair<int, int> to : g[i]) {
        ng.push_back(to);
      }
  dfs2(cyc, -1);
  dfs3(cyc, -1, 0);
  for (int i = 0; i < (int)(n); ++i)
    if (dsuParent(i) == cyc) {
      dfs4(i, -1);
      ++clen;
    }
  for (int v = cyc, p = -1;;) {
    a[pos] = asz[v];
    ind[pos] = v;
    for (pair<int, int> to : g[v])
      if (incyc[to.first] && to.first != p) {
        len[pos++] = to.second;
        p = v;
        v = to.first;
        break;
      }
    if (v == cyc) break;
  }
  for (int i = 0; i < (int)(n); ++i)
    if (incyc[i])
      ans[i] = distSum[cyc];
    else
      ans[i] = distSum[i];
  assert(pos == clen);
  for (int i = 0; i < (int)(clen + 1); ++i)
    a[clen + i] = a[i], len[clen + i] = len[i], ind[clen + i] = ind[i];
  int tot = 0;
  for (int i = 0; i < (int)(clen); ++i) tot += len[i];
  int mx = tot / 2;
  for (int z = 0; z < (int)(2); ++z) {
    int pos = 0;
    long long sum = 0, asum = 0, sumSum = 0;
    for (int i = 0; i < (int)(clen); ++i) {
      if (i && pos >= i) {
        sumSum -= asum * len[i - 1];
        sum -= len[i - 1];
        asum -= a[i];
      }
      if (pos < i) pos = i;
      while (sum + len[pos] <= mx) {
        sum += len[pos];
        asum += a[pos + 1];
        sumSum += sum * a[pos + 1];
        ++pos;
      }
      ans[ind[i]] += sumSum;
      ans2[ind[i]] += sumSum;
    }
    if (!z) {
      reverse(a, a + (2 * clen + 1));
      reverse(ind, ind + (2 * clen + 1));
      reverse(len, len + (2 * clen));
      len[2 * clen] = len[0];
      mx = tot - mx - 1;
    }
  }
  for (int i = 0; i < (int)(n); ++i)
    if (dsuParent(i) == cyc) {
      updVal = ans2[i];
      dfs5(i, -1);
    }
  for (int i = 0; i < (int)(n); ++i) printf("%I64d ", ans[i]);
  printf("\n");
  return 0;
}
