#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
int n;
long long Ans[200111];
vector<pair<int, int> > con[200111];
bool onc[200111];
int a[400111], an, d[400111];
long long pre_d[400111];
long long sum0[200111], sum1[200111];
bool vis[200111];
int dfs_pa[200111], dfs_pc[200111];
void dfs(int x, int pre = -1) {
  vis[x] = 1;
  for (int i = 0; i < con[x].size(); i++) {
    int u = con[x][i].first;
    if (u == pre) continue;
    if (vis[u]) {
      if (an > 0) continue;
      int p = x;
      while (true) {
        onc[p] = 1;
        d[an] = dfs_pc[p];
        a[an++] = p;
        if (p == u) break;
        p = dfs_pa[p];
      }
      d[an - 1] = con[x][i].second;
    } else
      dfs_pa[u] = x, dfs_pc[u] = con[x][i].second, dfs(u, x);
  }
}
int cur_g;
long long dis[200111];
vector<pair<int, long long> > v[200111];
int sz[200111], g[200111];
void dfs2(int x, int pre = -1, long long l = 0, long long sum = 0) {
  g[x] = cur_g;
  sum0[cur_g]++;
  sum1[cur_g] += l;
  dis[x] = l;
  v[cur_g].push_back(make_pair(x, l));
  sz[x] = 1;
  for (int i = 0; i < con[x].size(); i++) {
    int u = con[x][i].first;
    if (u == pre || onc[u]) continue;
    dfs2(u, x, l + con[x][i].second);
    sz[x] += sz[u];
  }
}
void dfs3(int x, int pre = -1, long long sum = 0) {
  Ans[x] = sum0[cur_g] * dis[x] - 2 * (sum + sz[x] * dis[x]);
  for (int i = 0; i < con[x].size(); i++) {
    int u = con[x][i].first;
    if (u == pre || onc[u]) continue;
    dfs3(u, x, sum + (sz[x] - sz[u]) * dis[x]);
  }
}
long long ans0[200111];
int main() {
  n = getnum();
  for (int i = 1; i <= n; i++) {
    int x, y, w;
    x = getnum(), y = getnum(), w = getnum();
    con[x].push_back(make_pair(y, w));
    con[y].push_back(make_pair(x, w));
  }
  dfs(1);
  for (int i = 0; i < an; i++) {
    cur_g = a[i];
    dfs2(a[i]);
    dfs3(a[i]);
  }
  int it = 0;
  for (int i = an; i < 2 * an; i++) d[i] = d[i - an], a[i] = a[i - an];
  for (int i = 1; i <= 2 * an; i++) pre_d[i] = pre_d[i - 1] + d[i - 1];
  while (pre_d[it] * 2 < pre_d[an]) it++;
  long long sum_l0 = 0, sum_l1 = 0, sum_r0 = 0, sum_r1 = 0;
  for (int i = 0; i < it; i++) {
    sum_r0 += sum0[a[i]];
    sum_r1 += pre_d[i] * sum0[a[i]];
  }
  for (int i = it; i < an; i++) {
    sum_l0 += sum0[a[i]];
    sum_l1 += (pre_d[i] - pre_d[an]) * sum0[a[i]];
  }
  for (int i = 0; i < an; i++) {
    while ((pre_d[it] - pre_d[i]) * 2 < pre_d[an]) {
      sum_l0 -= sum0[a[it]];
      sum_l1 -= (pre_d[it] - pre_d[an]) * sum0[a[it]];
      sum_r0 += sum0[a[it]];
      sum_r1 += pre_d[it] * sum0[a[it]];
      it++;
    }
    ans0[a[i]] = sum_r1 - sum_r0 * pre_d[i] + sum_l0 * pre_d[i] - sum_l1;
    sum_r0 -= sum0[a[i]];
    sum_r1 -= pre_d[i] * sum0[a[i]];
    sum_l0 += sum0[a[i]];
    sum_l1 += pre_d[i] * sum0[a[i]];
  }
  long long sum = 0;
  for (int i = 0; i < an; i++) sum += sum1[a[i]];
  for (int i = 1; i <= n; i++)
    putnum(sum + Ans[i] + dis[i] * (n - sum0[g[i]]) + ans0[g[i]]), putchar(' ');
  return 0;
}
