#include <bits/stdc++.h>
using namespace std;
namespace output {
void __(short x) { cout << x; }
void __(unsigned x) { cout << x; }
void __(int x) { cout << x; }
void __(long long x) { cout << x; }
void __(unsigned long long x) { cout << x; }
void __(double x) { cout << x; }
void __(long double x) { cout << x; }
void __(char x) { cout << x; }
void __(const char* x) { cout << x; }
void __(const string& x) { cout << x; }
void __(bool x) { cout << (x ? "true" : "false"); }
template <class S, class T>
void __(const pair<S, T>& x) {
  __(1 ? "(" : ""), __(x.first), __(1 ? ", " : " "), __(x.second),
      __(1 ? ")" : "");
}
template <class T>
void __(const vector<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const set<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const multiset<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class S, class T>
void __(const map<S, T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
void pr() { cout << "\n"; }
template <class S, class... T>
void pr(const S& a, const T&... b) {
  __(a);
  if (sizeof...(b)) __(' ');
  pr(b...);
}
}  // namespace output
using namespace output;
const int MN = 2e5 + 5;
int N, i, x, y, w, vs[MN], st[MN], ring[MN];
long long nxt[MN], ans[MN], sz[MN], dis[MN], len, idk[MN];
vector<pair<int, int> > adj[MN];
stack<int> s;
vector<int> cyc;
void detect(int n, int p) {
  vs[n] = 1;
  st[n] = 1;
  s.push(n);
  for (auto v : adj[n]) {
    if (v.first == p) continue;
    if (!vs[v.first]) detect(v.first, n);
    if (st[v.first]) {
      while (s.size() && s.top() != v.first) {
        cyc.push_back(s.top());
        s.pop();
      }
      cyc.push_back(s.top());
      s.pop();
    }
  }
  st[n] = 0;
  if (s.size() && s.top() == n) s.pop();
}
void dfs(int n, int p) {
  sz[n] = 1;
  for (auto v : adj[n]) {
    if (v.first == p || ring[v.first]) continue;
    dfs(v.first, n);
    sz[n] += sz[v.first];
    ans[n] += 1LL * v.second * sz[v.first];
    ans[n] += ans[v.first];
  }
}
void dfs2(int n, int p, long long up) {
  long long acc = 0;
  for (auto v : adj[n]) {
    if (v.first == p) {
      up += 1LL * v.second * (N - sz[n]);
      ans[n] += up;
      continue;
    }
    if (ring[v.first]) continue;
    acc += ans[v.first] + 1LL * v.second * sz[v.first];
  }
  for (auto v : adj[n]) {
    if (v.first == p || ring[v.first]) continue;
    dfs2(v.first, n, up + acc - ans[v.first] - 1LL * v.second * sz[v.first]);
  }
}
void prop(int n, int p, long long val) {
  ans[n] += val;
  for (auto v : adj[n]) {
    if (v.first == p || ring[v.first]) continue;
    prop(v.first, n, val);
  }
}
int main() {
  for (scanf("%d", &N), i = 1; i <= N; i++) {
    scanf("%d%d%d", &x, &y, &w);
    adj[x].push_back({y, w});
    adj[y].push_back({x, w});
  }
  detect(1, 0);
  for (auto v : cyc) ring[v] = 1;
  len = 0;
  for (i = 1; i < (int)cyc.size(); i++) {
    for (auto v : adj[cyc[i]]) {
      if (v.first == cyc[i - 1]) {
        dis[cyc[i]] = dis[v.first] + v.second;
        idk[cyc[i]] = v.second;
        nxt[cyc[i - 1]] = v.second;
        len += v.second;
        break;
      }
    }
  }
  for (auto v : adj[cyc[0]]) {
    if (v.first == cyc.back()) {
      len += v.second;
      nxt[cyc.back()] = v.second;
      idk[cyc[0]] = v.second;
      break;
    }
  }
  long long sigma = 0;
  for (auto v : cyc) {
    dfs(v, 0);
    dfs2(v, 0, 0);
    sigma += ans[v];
  }
  for (auto v : cyc) {
    prop(v, 0, sigma - ans[v]);
  }
  long long ls = sz[cyc[0]], rs = 0, lsm = 0, rsm = 0, j, dist = idk[cyc[0]];
  for (i = (int)cyc.size() - 1; i > 0; i--) {
    rs += sz[cyc[i]];
    rsm += dist * sz[cyc[i]];
    dist += idk[cyc[i]];
  }
  dist = 0;
  for (i = j = 0; i < (int)cyc.size(); i++) {
    while ((dist + nxt[cyc[j]]) * 2 <= len) {
      dist += nxt[cyc[j]];
      j = (j + 1) % cyc.size();
      long long dis2 = len - dist;
      rs -= sz[cyc[j]];
      rsm -= 1LL * dis2 * sz[cyc[j]];
      ls += sz[cyc[j]];
      lsm += 1LL * dist * sz[cyc[j]];
    }
    ls -= sz[cyc[i]];
    rs += sz[cyc[i]];
    long long cur = lsm + rsm;
    prop(cyc[i], 0, cur);
    if (i + 1 != cyc.size()) {
      long long nxt = dis[cyc[i + 1]] - dis[cyc[i]];
      lsm -= ls * nxt;
      rsm += rs * nxt;
      dist -= nxt;
    }
  }
  for (i = 1; i <= N; i++) printf("%lld ", ans[i]);
  pr();
  return 0;
}
