#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> mp[200001];
int stk[200001], vst[200001], edgew[400001];
pair<int, int> dfs(int k, int p, int curd) {
  vst[k] = curd;
  stk[curd] = k;
  for (auto c : mp[k])
    if (c.first != p) {
      edgew[curd] = c.second;
      if (vst[c.first]) return make_pair(vst[c.first], curd);
      pair<int, int> res = dfs(c.first, k, curd + 1);
      if (res.first) return res;
    }
  vst[k] = 0;
  return make_pair(0, 0);
}
bool ban[200001];
int sts[200001];
pair<int, long long> traverse(int k, int p) {
  int ret1 = 1;
  long long ret2 = 0;
  for (auto c : mp[k])
    if (c.first != p && !ban[c.first]) {
      pair<int, long long> res = traverse(c.first, k);
      ret1 += res.first;
      ret2 += res.second + c.second * res.first;
    }
  return make_pair(ret1, ret2);
}
long long ans[200001], weight[200001];
int siz[400001];
void subtree_add(int k, int p, long long val) {
  ans[k] += val;
  for (auto c : mp[k])
    if (c.first != p && !ban[c.first]) subtree_add(c.first, k, val);
}
void setvw(int k, int p, int val, int siz) {
  ans[k] += (long long)val * siz;
  for (auto c : mp[k])
    if (c.first != p && !ban[c.first]) setvw(c.first, k, val + c.second, siz);
}
void traverse2(int k, int p) {
  siz[k] = 1;
  weight[k] = 0;
  for (auto c : mp[k])
    if (c.first != p && !ban[c.first]) {
      traverse2(c.first, k);
      siz[k] += siz[c.first];
      weight[k] += weight[c.first] + c.second * siz[c.first];
    }
}
void down_propgate(int k, int p, int num) {
  if (p) ans[k] += ans[p];
  for (auto c : mp[k])
    if (c.first != p && !ban[c.first]) {
      ans[c.first] = weight[k] - (weight[c.first] + c.second * siz[c.first]) +
                     (num - siz[c.first]) * c.second;
      if (c.first != p && !ban[c.first]) down_propgate(c.first, k, num);
    }
  ans[k] += weight[k];
}
long long cycleans[200001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int a, b, t;
    scanf("%d%d%d", &a, &b, &t);
    mp[a].push_back(make_pair(b, t));
    mp[b].push_back(make_pair(a, t));
  }
  pair<int, int> tmp = dfs(1, 0, 1);
  for (int i = tmp.first; i <= tmp.second; ++i) {
    stk[i - tmp.first] = stk[i];
    edgew[i - tmp.first] = edgew[i];
  }
  int cyclelen = tmp.second - tmp.first + 1;
  long long totweight = 0;
  for (int i = 0; i < cyclelen; ++i) {
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        true;
    traverse2(stk[i], 0);
    down_propgate(stk[i], 0, siz[stk[i]]);
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        false;
  }
  for (int i = 0; i < cyclelen; ++i) {
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        true;
    pair<int, long long> tmp = traverse(stk[i], 0);
    siz[i] = tmp.first;
    totweight += weight[i] = tmp.second;
    setvw(stk[i], 0, 0, n - siz[i]);
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        false;
  }
  for (int i = 0; i < cyclelen; ++i) cycleans[i] += totweight - weight[i];
  for (int i = cyclelen; i < cyclelen + cyclelen; ++i) {
    edgew[i] = edgew[i - cyclelen];
    siz[i] = siz[i - cyclelen];
  }
  for (int i = 1; i < cyclelen + cyclelen; ++i) {
    edgew[i] += edgew[i - 1];
    siz[i] += siz[i - 1];
  }
  long long sum1 = 0, sum2 = 0;
  int pos = 0;
  for (int i = 1; i < cyclelen; ++i)
    sum2 +=
        (long long)(edgew[cyclelen - 1] - edgew[i - 1]) * (siz[i] - siz[i - 1]);
  for (int i = 0;;) {
    while (pos + 1 < i + cyclelen && edgew[i + cyclelen - 1] - edgew[pos] >
                                         edgew[pos] - (i ? edgew[i - 1] : 0)) {
      sum1 += (long long)(edgew[pos] - (i ? edgew[i - 1] : 0)) *
              (siz[pos + 1] - siz[pos]);
      sum2 -= (long long)(edgew[i + cyclelen - 1] - edgew[pos]) *
              (siz[pos + 1] - siz[pos]);
      ++pos;
    }
    cycleans[i] += sum1 + sum2;
    if (i == cyclelen - 1) break;
    if (pos == i) {
      sum1 += (long long)(edgew[pos] - (i ? edgew[i - 1] : 0)) *
              (siz[pos + 1] - siz[pos]);
      sum2 -= (long long)(edgew[i + cyclelen - 1] - edgew[pos]) *
              (siz[pos + 1] - siz[pos]);
      ++pos;
    }
    sum1 -= (edgew[i] - (i ? edgew[i - 1] : 0)) * (siz[pos] - siz[i]);
    sum2 +=
        (edgew[i] - (i ? edgew[i - 1] : 0)) * (siz[i + cyclelen] - siz[pos]);
    ++i;
  }
  for (int i = 0; i < cyclelen; ++i) {
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        true;
    subtree_add(stk[i], 0, cycleans[i]);
    ((i + 1) % cyclelen)[stk][ban] = ((i + cyclelen - 1) % cyclelen)[stk][ban] =
        false;
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", ans[i]);
  printf("\n");
  return 0;
}
