#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) (x).begin(),(x).end()

struct edge{
	int to, cost;
	edge() {}
	edge(int _to, int _cost) {
		to = _to, cost = _cost;
	}
};

const int MAXN = 2e5 + 10;
int n;
vector<edge> g[MAXN];

int cycle[MAXN], rcycle[MAXN], topCycle = 0;
int par[MAXN], tin[MAXN], timer = 0;
int used[MAXN];
ll ans[MAXN], fans[MAXN];

int h[MAXN], sz[MAXN];
int fcost[MAXN][2];
int fullCycle = 0;

void buildCost() {
	for (int v = 0; v < n; v++) {
		if (!used[v]) continue;
		int posV = rcycle[v];
		for (auto [to, cost] : g[v]) {
			if (!used[to]) continue;
			int posU = rcycle[to];
			if (posU == posV - 1 || posU - (topCycle - 1) == posV) {
				fcost[posV][0] = cost;
			} else {
				fcost[posV][1] = cost;
			}
		}
	}
}

void dfsCycle(int v, int p) {
	used[v] = true;
	tin[v] = timer++;
	par[v] = p;
	for (auto [to, cost] : g[v]) {
		if (to == p) continue;
		if (!used[to]) {
			dfsCycle(to, v);
		}
	}
}

void findCycle() {
	fill(used, used + n, false);
	dfsCycle(0, -1);
	for (int v = 0; v < n; v++) {
		bool ok = false;
		for (auto [to, cost] : g[v]) {
			if (to == par[v]) continue;
			if (par[to] == v) continue;
			if (tin[v] < tin[to]) swap(v, to);
			while (v != to) {
				cycle[topCycle++] = v;
				v = par[v];
			}
			cycle[topCycle++] = v;
			ok = true;
			break;
		}
		if (ok) break;
	}
	fill(used, used + n, false);
	for (int i = 0; i < topCycle; i++) {
		used[cycle[i]] = true;
	}
	for (int i = 0; i < topCycle; i++) {
		rcycle[cycle[i]] = i;
	}
	buildCost();
}

void dfsBuild(int v, int p) {
	sz[v] = 1;
	fans[v] = 0;
	for (auto [to, cost] : g[v]) {
		if (to == p) continue;
		if (used[to]) continue;
		h[to] = h[v] + cost;
		dfsBuild(to, v);
		sz[v] += sz[to];
		fans[v] += fans[to] + sz[to] * cost;
	}
}

struct myDeque{
	deque<int> cost;
	deque<int> v;
	int fullSz;
	int fullCost;
	ll ans;
	myDeque() {
		cost = {};
		v = {};
		fullCost = 0;
		fullSz = 0;
		ans = 0;
	}
	void addR(int _cost, int _v) {
		ans += (fullCost + _cost) * sz[_v] + fans[_v];
		fullCost += _cost;
		fullSz += sz[_v];
		cost.push_back(_cost);
		v.push_back(_v);
	}
	void delR() {
		int _cost = cost.back();
		int _v = v.back();
		cost.pop_back();
		v.pop_back();
		fullCost -= _cost;
		fullSz -= sz[_v];
		ans -= (fullCost + _cost) * sz[_v] + fans[_v];
	}
	void addL(int _cost, int _v) {
		fullCost += _cost;
		fullSz += sz[_v];
		ans += fullSz * _cost + fans[_v];
		cost.push_front(_cost);
		v.push_front(_v);
	}
	void delL() {
		int _cost = cost.front();
		int _v = v.front();
		cost.pop_front();
		v.pop_front();
		ans -= fullSz * _cost + fans[_v];
		fullCost -= _cost;
		fullSz -= sz[_v];
	}
	bool empty() {
		return v.empty();
	}
};

void balance(myDeque & L, myDeque & R) {
	while (true) {
		if (!L.empty() && L.fullCost > fullCycle - L.fullCost) {
			int v = L.v.back();
			int pos = rcycle[v];
			L.delR();
			R.addR(fcost[pos][0], v);
		} else if (!R.empty() && R.fullCost > fullCycle - R.fullCost) {
			int v = R.v.back();
			int pos = rcycle[v];
			R.delR();
			L.addR(fcost[pos][1], v);
		} else {
			return;
		}
	}
	assert(false);
}

void makeNxt(myDeque & L, myDeque & R, int pos, int v) {
	if (!R.empty()) {
		R.delL();
	} else {
		L.delR();
	}
	L.addL(fcost[pos][1], v);
}

void buildCycle() {
	for (int i = 0; i < topCycle; i++) {
		dfsBuild(cycle[i], -1);
	}
	myDeque L, R;
	for (int i = 0; i < topCycle; i++) {
		fullCycle += fcost[i][1];
	}
	for (int i = 1; i < topCycle; i++) {
		R.addR(fcost[i][0], cycle[i]);
	}
	for (int i = 0; i < topCycle; i++) {
		balance(L, R);
		ans[cycle[i]] = L.ans + R.ans + fans[cycle[i]];
		if (i + 1 < topCycle) makeNxt(L, R, i, cycle[i]);
	}
}

void dfsSolve(int v, int p) {
	for (auto [to, cost] : g[v]) {
		if (used[to]) continue;
		if (to == p) continue;
		ans[to] += ans[v] + (n - 2 * sz[to]) * cost;
		dfsSolve(to, v);
	}
}

void solveOther() {
	for (int i = 0; i < topCycle; i++) {
		dfsSolve(cycle[i], -1);
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, v, cost;
		cin >> u >> v >> cost;
		u--;
		v--;
		g[u].push_back({v, cost});
		g[v].push_back({u, cost});
	}
	findCycle();
	buildCycle();
	solveOther();
	for (int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}


#include <stack>
#include <cstdio>
#include <vector>
#include <numeric>
#include <utility>
#include <algorithm>

using namespace std;

struct Root {
	int p, c;
	long long e, x;
	vector<int> v;
	Root(int p, long long e) : p(p), e(e) { }
};

const int MAXN = 200200;
bool oncirc[MAXN];
vector<pair<int, long long> > e[MAXN];
vector<Root> circ;
long long ans[MAXN];

bool mark[MAXN];

int dfs(int v, int p) {
	if (mark[v]) {
		return v;
	} else {
		mark[v] = true;
	}
	for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) {
		int w = it->first;
		if (w == p) {
			continue;
		}
		int t = dfs(w, v);
		if (t != -1) {
			circ.push_back(Root(w, it->second));
			return v == t ? -1 : t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

	dfs(0, -1);
	m = circ.size();
	for (int i = 0; i < m; ++i) {
//printf("%d--(%lld)--", circ[i].p, circ[i].e);
		oncirc[circ[i].p] = true;
	}
//puts("");

	return m;
}

Root* root;
long long dd[MAXN], cc[MAXN], ss[MAXN], xx[MAXN];

void gao1(int v, int p) {
	root->v.push_back(v);
	cc[v] = 1;
	ss[v] = 0;
	for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) {
		int w = it->first;
		if (w == p || oncirc[w]) {
			continue;
		}
		dd[w] = dd[v] + it->second;
		gao1(w, v);
		cc[v] += cc[w];
		ss[v] += ss[w] + cc[w] * it->second;
	}
}

void gao2(int v, int p, int n) {
	for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) {
		int w = it->first;
		if (w == p || oncirc[w]) {
			continue;
		}
		xx[w] = xx[v] + (ss[v] - (ss[w] + cc[w] * it->second)) + (n - cc[w]) * it->second;
		gao2(w, v, n);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	r.c = cc[r.p];
	gao2(r.p, -1, r.c);
	for (vector<int>::const_iterator it = r.v.begin(); it != r.v.end(); ++it) {
		ans[*it] = xx[*it] + ss[*it];
	}
	r.x = ans[r.p];
}

long long ee[MAXN + MAXN];

void calccirc(int n, int m) {
	long long circlen = 0;
	long long total = 0;
	long long cursum = 0;
	int curcnt = 0;
	int q = 0;

	for (int i = 0; i < m; ++i) {
		circlen += circ[i].e;
		total += circ[i].x;
		ee[i + 1 + m] = ee[i + 1] = circ[i].e;
	}
	ee[0] = 0;
	partial_sum(ee, ee + m + m + 1, ee);

	// init
	while (2 * (ee[q] - ee[0]) <= circlen) {
		cursum += (ee[q] - ee[0]) * circ[q % m].c;
		curcnt += circ[q % m].c;
		++q;
	}
	for (int i = q; i < m; ++i) {
		cursum += (circlen - (ee[i] - ee[0])) * circ[i % m].c;
	}
//printf("total = %lld; cursum = %lld; curcnt = %d; q = %d\n", total, cursum, curcnt, q);

	for (int i = 0; i < m; ++i) {
		// adjust i
		while (2 * (ee[q] - ee[i]) <= circlen) {
			cursum -= (circlen - 2 * (ee[q] - ee[i])) * circ[q % m].c;
			curcnt += circ[q % m].c;
			++q;
		}
//printf("[%d] cursum = %lld; curcnt = %d; curc.x = %lld, q = %d\n", circ[i].p, cursum, curcnt, circ[i].x, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
//printf("{%d} ans = %lld; dd = %lld; del = %lld; n - c = %d - %d\n", *it, ans[*it],  dd[*it], cursum + total - circ[i].x, n, circ[i].c);
			ans[*it] += cursum + total - circ[i].x + dd[*it] * (n - circ[i].c);
		}
		// shift i->i+1
		curcnt -= circ[i].c;
		cursum += (n - curcnt) * circ[i].e;
		cursum -= curcnt * circ[i].e;
	}
}

int main() {
	int n, m, a, b, c;

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d%d", &a, &b, &c);
		--a;
		--b;
		e[a].push_back(make_pair(b, c));
		e[b].push_back(make_pair(a, c));
	}

	m = findcirc(n);
	for (int i = 0; i < m; ++i) {
		calctree(circ[i]);
	}
	calccirc(n, m);

	for (int i = 0; i < n; ++i) {
		printf("%I64d%c", ans[i], i == n - 1 ? '\n' : ' ');
//		printf("%lld%c", ans[i], i == n - 1 ? '\n' : ' ');
	}

	return 0;
}


#include <vector>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include <set>
#include<map>
#include<string>

using namespace std;
template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; }
template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; }
#define max(a, b) (a > b?a:b)
#define min(a, b) (a < b?a:b)

#define MS(a, v)    memset(a, v, sizeof(a))

typedef long long LL;

const int N = 200010;
const int oo = 10000 * 10000 * 10;

int n;

vector<int> e[N];
bool inc[N];

int cn;
int cp[N];
int next[N];
LL cw[N];
LL num[N];
LL dis[N];         //dis to the root in cir
LL up[N];
LL dn[N];
int proot[N];
bool visited[N];
bool find_cir(int p, int u)
{
//    printf("%d %d\n", p, u);
    int i, j, k;
    visited[u] = true;
    for(i = 0; i < e[u].size();i += 2)
    {
        int v = e[u][i];
        int w = e[u][i + 1];
        if( v != p )
        {
            if( !visited[v] )
            {
                next[v] = u;
                cw[v] = w;
                if( find_cir(u, v) )
                    return true;
            }
            else
            {
//                printf("%d %d\n", u, v);
                cn = 0;
                cw[v] = w;
                for(j = u;j != v;j = next[j])
                    cp[cn++] = j;
                cp[cn++] = v;
//                show(cp, cn);
                MS(inc, 0);
                for(j = 0;j < cn;++j)
                    inc[ cp[j] ] = true;
                return true;
            }
        }
    }
    return false;
}

//dis num dn
// set dis[root] = 0
void cal_dn( int u )
{
    visited[u] = true;
    dn[u] = 0;
    num[u] = 1;
    for(int i = 0; i < e[u].size();i += 2 )
    {
        int v = e[u][i];
        int c = e[u][i + 1];
        if( inc[v] || visited[v] )    continue;
        dis[v] = dis[u] + c;
        cal_dn(v);
        dn[u] += dn[v] + (LL)num[v] * c;
        num[u] += num[v];
    }
}

int root;
//set up[root] = 0;
void cal_up(int p)
{
    visited[p] = true;
    proot[p] = root;
    for(int i = 0; i < e[p].size();i += 2)
    {
        int u = e[p][i];
        int c = e[p][i + 1];
        if( inc[u] || visited[u] )    continue;
//        if( p == root )
//            up[u] = dn[p] - ( dn[u] + num[u] * c ) + c * (num[p] - num[u]);
//        else
//            up[u] = up[p] + (num[root] - num[u]) * c;
        up[u] = dn[p] + up[p] - dn[u] - num[u] * c + (num[root] - num[u]) * c;
        cal_up(u);
    }
}

// ans of p in cir saved in up
void cal_cir()
{
    int i, j, k;
    int ln;
    LL lw, rw;
    int lp, rp;
    LL lnum, rnum;
    LL ldis = 0, rdis = 0;
    lw = 0, rw = 0;
    lp = 1, rp = 0;
    lnum = 0;
    rnum = 0;
    for(i = cn - 1; i >= 1;--i)
    {
        ldis += cw[ cp[i] ];
        lw = lw + num[ cp[i] ] * ldis;
        lnum += num[ cp[i] ];
    }
    for(i = 0; i < cn;++i)
    {
        while(1)
        {
            if( rdis + cw[ cp[rp] ] < ldis )
            {
//                printf("t     :%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
//                printf("aftert:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
            }
            else
            {
//                printf("get:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                up[ cp[i] ] = lw + rw;
                break;
            }
        }
        if( i + 1 < cn && lp == i + 1 )
        {
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
        }

        lnum += num[ cp[i] ];
        lw += lnum * cw[ cp[i] ];
        ldis += cw[ cp[i] ];

        rw -= rnum * cw[ cp[i] ];
        rnum -= num[ cp[(i + 1)%cn] ];
        rdis -= cw[ cp[i] ];
//        printf("end:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
    }
}

void solve()
{
    int i, j, k;
    MS(visited, 0);
    find_cir(1, 1);
//    puts("tt");
//    show(cp, cn);
//    show(cw + 1, n);
//    show(num + 1, n);
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        dis[ cp[i] ] = 0;
        cal_dn(cp[i]);
    }
//    puts("ok");
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        root = cp[i];
        up[root] = 0;
        cal_up( root );
    }
//    puts("ok");
    cal_cir();

//    show(cp, n);
//    show(cw + 1, n);
//    show(num + 1, n);

//    printf("up:");  show(up + 1, n);
//    printf("dn:");  show(dn + 1, n);
//    printf("rt:");  show(proot + 1, n);

    LL dn_all = 0;
    for(i = 0; i < cn;++i)
        dn_all += dn[ cp[i] ];
    for(i = 1; i <= n;++i)
    {
        if( i != 1 )    printf(" ");
        if( inc[i] )    printf("%lld", dn_all + up[i]);
        else    printf("%lld", up[i] + dn[i] + dn_all - dn[ proot[i] ] + up[ proot[i] ] + dis[i] * (n - num[ proot[i] ] ) );
    }
    putchar(10);
}

int main()
{
//        freopen("in", "r", stdin);
//        freopen("out1","w",stdout);
    int i, j, cas = 0;
    scanf("%d", &n);

    for(i = 0; i < n;++i)
    {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        e[u].push_back(v);
        e[u].push_back(c);
        e[v].push_back(u);
        e[v].push_back(c);
    }
    solve();
    return 0;
}


#include <vector>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include <set>
#include<map>
#include<string>

using namespace std;
template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; }
template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; }
#define max(a, b) (a > b?a:b)
#define min(a, b) (a < b?a:b)

#define MS(a, v)    memset(a, v, sizeof(a))

typedef long long LL;

const int N = 200010;
const int M = 5000;
const int oo = 10000 * 10000 * 10;

int n;

vector<int> e[N];
bool inc[N];

int cn;
int cp[N];
int next[N];
int cw[N];
LL num[N];
LL dis[N];         //dis to the root in cir
LL up[N];
LL dn[N];
int proot[N];
bool visited[N];
bool find_cir(int p, int u)
{
//    printf("%d %d\n", p, u);
    int i, j, k;
    visited[u] = true;
    for(i = 0; i < e[u].size();i += 2)
    {
        int v = e[u][i];
        int w = e[u][i + 1];
        if( v != p )
        {
            if( !visited[v] )
            {
                next[v] = u;
                cw[v] = w;
                if( find_cir(u, v) )
                    return true;
            }
            else
            {
//                printf("%d %d\n", u, v);
                cn = 0;
                cw[v] = w;
                for(j = u;j != v;j = next[j])
                    cp[cn++] = j;
                cp[cn++] = v;
//                show(cp, cn);
                MS(inc, 0);
                for(j = 0;j < cn;++j)
                    inc[ cp[j] ] = true;
                return true;
            }
        }
    }
    return false;
}

//dis num dn
// set dis[root] = 0
void cal_dn( int u )
{
    visited[u] = true;
    dn[u] = 0;
    num[u] = 1;
    for(int i = 0; i < e[u].size();i += 2 )
    {
        int v = e[u][i];
        int c = e[u][i + 1];
        if( inc[v] || visited[v] )    continue;
        dis[v] = dis[u] + c;
        cal_dn(v);
        dn[u] += dn[v] + (LL)num[v] * c;
        num[u] += num[v];
    }
}

int root;
//set up[root] = 0;
void cal_up(int p)
{
    visited[p] = true;
    proot[p] = root;
    for(int i = 0; i < e[p].size();i += 2)
    {
        int u = e[p][i];
        int c = e[p][i + 1];
        if( inc[u] || visited[u] )    continue;
        if( p == root )
            up[u] = dn[p] - ( dn[u] + num[u] * c ) + c * (num[p] - num[u]);
        else
            up[u] = up[p] + (num[root] - num[u]) * c;
        cal_up(u);
    }
}

// ans of p in cir saved in up
void cal_cir()
{
    int i, j, k;
    int ln;
    LL lw, rw;
    int lp, rp;
    LL lnum, rnum;
    LL ldis = 0, rdis = 0;
    lw = 0, rw = 0;
    lp = 1, rp = 0;
    lnum = 0;
    rnum = 0;
    for(i = cn - 1; i >= 1;--i)
    {
        ldis += cw[ cp[i] ];
        lw = lw + num[ cp[i] ] * ldis;
        lnum += num[ cp[i] ];
    }
    for(i = 0; i < cn;++i)
    {
        while(1)
        {
            if( rw + num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis) < ldis )
            {
//                printf("t     :%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
//                printf("aftert:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
            }
            else
            {

                up[ cp[i] ] = lw + rw;
                break;
            }
        }
        if( i + 1 < cn && lp == i + 1 )
        {
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
        }

        lnum += num[ cp[i] ];
        lw += lnum * cw[ cp[i] ];
        ldis += cw[ cp[i] ];

        rw -= rnum * cw[ cp[i] ];
        rnum -= num[ cp[(i + 1)%cn] ];
        rdis -= cw[ cp[i] ];
    }
}

void solve()
{
    int i, j, k;
    MS(visited, 0);
    find_cir(1, 1);
//    puts("tt");
//    show(cp, cn);
//    show(cw + 1, n);
//    show(num + 1, n);
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        dis[ cp[i] ] = 0;
        cal_dn(cp[i]);
    }
//    puts("ok");
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        root = cp[i];
        up[root] = 0;
        cal_up( root );
    }
//    puts("ok");
    cal_cir();

//    show(cp, n);
//    show(cw + 1, n);
//    show(num + 1, n);

//    printf("up:");  show(up + 1, n);
//    printf("dn:");  show(dn + 1, n);
//    printf("rt:");  show(proot + 1, n);

    LL dn_all = 0;
    for(i = 0; i < cn;++i)
        dn_all += dn[ cp[i] ];
    for(i = 1; i <= n;++i)
    {
        if( i != 1 )    printf(" ");
        if( inc[i] )    printf("%lld", dn_all + up[i]);
        else    printf("%lld", up[i] + dn[i] + dn_all - dn[ proot[i] ] + up[ proot[i] ] + dis[i] * (n - num[ proot[i] ] ) );
    }
    putchar(10);
}

int main()
{
//        freopen("in", "r", stdin);
//        freopen("out1","w",stdout);
    int i, j, cas = 0;
    scanf("%d", &n);

    for(i = 0; i < n;++i)
    {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        e[u].push_back(v);
        e[u].push_back(c);
        e[v].push_back(u);
        e[v].push_back(c);
    }
    solve();
    return 0;
}


#include <vector>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include <set>
#include<map>
#include<string>

using namespace std;
template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; }
template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; }
#define max(a, b) (a > b?a:b)
#define min(a, b) (a < b?a:b)

#define MS(a, v)    memset(a, v, sizeof(a))

typedef long long LL;

const int N = 200010;
const int M = 5000;
const int oo = 10000 * 10000 * 10;

int n;

vector<int> e[N];
bool inc[N];

int cn;
int cp[N];
int next[N];
int cw[N];
LL num[N];
LL dis[N];         //dis to the root in cir
LL up[N];
LL dn[N];
int proot[N];
bool visited[N];
bool find_cir(int p, int u)
{
//    printf("%d %d\n", p, u);
    int i, j, k;
    visited[u] = true;
    for(i = 0; i < e[u].size();i += 2)
    {
        int v = e[u][i];
        int w = e[u][i + 1];
        if( v != p )
        {
            if( !visited[v] )
            {
                next[v] = u;
                cw[v] = w;
                if( find_cir(u, v) )
                    return true;
            }
            else
            {
//                printf("%d %d\n", u, v);
                cn = 0;
                cw[v] = w;
                for(j = u;j != v;j = next[j])
                    cp[cn++] = j;
                cp[cn++] = v;
//                show(cp, cn);
                MS(inc, 0);
                for(j = 0;j < cn;++j)
                    inc[ cp[j] ] = true;
                return true;
            }
        }
    }
    return false;
}

//dis num dn
// set dis[root] = 0
void cal_dn( int u )
{
    visited[u] = true;
    dn[u] = 0;
    num[u] = 1;
    for(int i = 0; i < e[u].size();i += 2 )
    {
        int v = e[u][i];
        int c = e[u][i + 1];
        if( inc[v] || visited[v] )    continue;
        dis[v] = dis[u] + c;
        cal_dn(v);
        dn[u] += dn[v] + (LL)num[v] * c;
        num[u] += num[v];
    }
}

int root;
//set up[root] = 0;
void cal_up(int p)
{
    visited[p] = true;
    proot[p] = root;
    for(int i = 0; i < e[p].size();i += 2)
    {
        int u = e[p][i];
        int c = e[p][i + 1];
        if( inc[u] || visited[u] )    continue;
        if( p == root )
            up[u] = dn[p] - ( dn[u] + num[u] * c ) + c * (num[p] - num[u]);
        else
            up[u] = up[p] + (num[root] - num[u]) * c;
        cal_up(u);
    }
}

// ans of p in cir saved in up
void cal_cir()
{
    int i, j, k;
    int ln;
    LL lw, rw;
    int lp, rp;
    LL lnum, rnum;
    LL ldis = 0, rdis = 0;
    lw = 0, rw = 0;
    lp = 1, rp = 0;
    lnum = 0;
    rnum = 0;
    for(i = cn - 1; i >= 1;--i)
    {
        ldis += cw[ cp[i] ];
        lw = lw + num[ cp[i] ] * ldis;
        lnum += num[ cp[i] ];
    }
    for(i = 0; i < cn;++i)
    {
        while(1)
        {
            if( rdis + cw[ cp[rp] ] < ldis )
            {
//                printf("t     :%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
//                printf("aftert:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
            }
            else
            {
//                printf("get:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                up[ cp[i] ] = lw + rw;
                break;
            }
        }
        if( i + 1 < cn && lp == i + 1 )
        {
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
        }

        lnum += num[ cp[i] ];
        lw += lnum * cw[ cp[i] ];
        ldis += cw[ cp[i] ];

        rw -= rnum * cw[ cp[i] ];
        rnum -= num[ cp[(i + 1)%cn] ];
        rdis -= cw[ cp[i] ];
//        printf("end:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
    }
}

void solve()
{
    int i, j, k;
    MS(visited, 0);
    find_cir(1, 1);
//    puts("tt");
//    show(cp, cn);
//    show(cw + 1, n);
//    show(num + 1, n);
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        dis[ cp[i] ] = 0;
        cal_dn(cp[i]);
    }
//    puts("ok");
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        root = cp[i];
        up[root] = 0;
        cal_up( root );
    }
//    puts("ok");
    cal_cir();

//    show(cp, n);
//    show(cw + 1, n);
//    show(num + 1, n);

//    printf("up:");  show(up + 1, n);
//    printf("dn:");  show(dn + 1, n);
//    printf("rt:");  show(proot + 1, n);

    LL dn_all = 0;
    for(i = 0; i < cn;++i)
        dn_all += dn[ cp[i] ];
    for(i = 1; i <= n;++i)
    {
        if( i != 1 )    printf(" ");
        if( inc[i] )    printf("%lld", dn_all + up[i]);
        else    printf("%lld", up[i] + dn[i] + dn_all - dn[ proot[i] ] + up[ proot[i] ] + dis[i] * (n - num[ proot[i] ] ) );
    }
    putchar(10);
}

int main()
{
//        freopen("in", "r", stdin);
//        freopen("out1","w",stdout);
    int i, j, cas = 0;
    scanf("%d", &n);

    for(i = 0; i < n;++i)
    {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        e[u].push_back(v);
        e[u].push_back(c);
        e[v].push_back(u);
        e[v].push_back(c);
    }
    solve();
    return 0;
}


#include <vector>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include <set>
#include<map>
#include<string>

using namespace std;
template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; }
template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; }
#define max(a, b) (a > b?a:b)
#define min(a, b) (a < b?a:b)

#define MS(a, v)    memset(a, v, sizeof(a))

typedef long long LL;

const int N = 200010;
const int M = 5000;
const int oo = 10000 * 10000 * 10;

int n;

vector<int> e[N];
bool inc[N];

int cn;
int cp[N];
int next[N];
int cw[N];
LL num[N];
LL dis[N];         //dis to the root in cir
LL up[N];
LL dn[N];
int proot[N];
bool visited[N];
bool find_cir(int p, int u)
{
//    printf("%d %d\n", p, u);
    int i, j, k;
    visited[u] = true;
    for(i = 0; i < e[u].size();i += 2)
    {
        int v = e[u][i];
        int w = e[u][i + 1];
        if( v != p )
        {
            if( !visited[v] )
            {
                next[v] = u;
                cw[v] = w;
                if( find_cir(u, v) )
                    return true;
            }
            else
            {
//                printf("%d %d\n", u, v);
                cn = 0;
                cw[v] = w;
                for(j = u;j != v;j = next[j])
                    cp[cn++] = j;
                cp[cn++] = v;
//                show(cp, cn);
                MS(inc, 0);
                for(j = 0;j < cn;++j)
                    inc[ cp[j] ] = true;
                return true;
            }
        }
    }
    return false;
}

//dis num dn
// set dis[root] = 0
void cal_dn( int u )
{
    visited[u] = true;
    dn[u] = 0;
    num[u] = 1;
    for(int i = 0; i < e[u].size();i += 2 )
    {
        int v = e[u][i];
        int c = e[u][i + 1];
        if( inc[v] )    continue;
        dis[v] = dis[u] + c;
        cal_dn(v);
        dn[u] += dn[v] + (LL)num[v] * c;
        num[u] += num[v];
    }
}

int root;
//set up[root] = 0;
void cal_up(int p)
{
    visited[p] = true;
    proot[p] = root;
    for(int i = 0; i < e[p].size();i += 2)
    {
        int u = e[p][i];
        int c = e[p][i + 1];
        if( inc[u] )    continue;
        if( p == root )
            up[u] = dn[p] - ( dn[u] + num[u] * c ) + c * (num[p] - num[u]);
        else
            up[u] = up[p] + (num[root] - num[u]) * c;
        cal_up(u);
    }
}

// ans of p in cir saved in up
void cal_cir()
{
    int i, j, k;
    int ln;
    LL lw, rw;
    int lp, rp;
    LL lnum, rnum;
    LL ldis = 0, rdis = 0;
    lw = 0, rw = 0;
    lp = 1, rp = 0;
    lnum = 0;
    rnum = 0;
    for(i = cn - 1; i >= 1;--i)
    {
        ldis += cw[ cp[i] ];
        lw = lw + num[ cp[i] ] * ldis;
        lnum += num[ cp[i] ];
    }
    for(i = 0; i < cn;++i)
    {
        while(1)
        {
            if( rw + num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis) < ldis )
            {
//                printf("t     :%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
//                printf("aftert:%d %d %d %lld %lld %lld %lld\n", i, lp, rp, lw, rw, ldis, rdis);
            }
            else
            {

                up[ cp[i] ] = lw + rw;
                break;
            }
        }
        if( i + 1 < cn && lp == i + 1 )
        {
                rw += num[ cp[lp] ] * ( cw[ cp[rp] ] + rdis);
                rnum += num[ cp[lp] ];
                rdis += cw[ cp[rp] ];
                rp = (rp + 1) % cn;

                lw -= num[ cp[lp] ] * ldis ;
                lnum -= num[ cp[lp] ];
                ldis -= cw[ cp[lp] ];
                lp = (lp + 1 ) % cn;
        }

        lnum += num[ cp[i] ];
        lw += lnum * cw[ cp[i] ];
        ldis += cw[ cp[i] ];

        rw -= rnum * cw[ cp[i] ];
        rnum -= num[ cp[(i + 1)%cn] ];
        rdis -= cw[ cp[i] ];
    }
}

void solve()
{
    int i, j, k;
    MS(visited, 0);
    find_cir(1, 1);
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        dis[ cp[i] ] = 0;
        cal_dn(cp[i]);
    }
//    puts("ok");
    MS(visited, 0);
    for(i = 0; i < cn;++i)
    {
        root = cp[i];
        up[root] = 0;
        cal_up( root );
    }

    cal_cir();
//    show(cp, n);
//    show(cw + 1, n);
//    show(num + 1, n);
    for(i = 1; i <= n;++i)
    {
        if( i != 1 )    printf(" ");
        if( inc[i] )    printf("%lld", up[i]);
        else    printf("%lld", up[i] + dn[i] + up[ proot[i] ] + dis[i] * (cn - 1) );
    }
    putchar(10);
}

int main()
{
//        freopen("in", "r", stdin);
//        freopen("out1","w",stdout);
    int i, j, cas = 0;
    scanf("%d", &n);

    for(i = 0; i < n;++i)
    {
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        e[u].push_back(v);
        e[u].push_back(c);
        e[v].push_back(u);
        e[v].push_back(c);
    }
    solve();
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010?12?14?, ??7:12
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
long long ans[MAXN];

int Dfs2(int pos, long long &val, long long len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, long long val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    long long val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, long long val, int num, long long len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, long long val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    long long totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    long long llen = 0, rlen = 0;
    long long lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < (int)circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = (int)circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= (int)circle.size();

//    for (int i = 0; i < (int)circle.size(); i++)
//        printf("%d\n", circle[i].first);
    for (int i = 0; i < (int)circle.size(); i++){
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[(i + 1) % (int)circle.size()].first ];
        rlen -= circle[i].second;
//        puts("lp, lsum, lval, llen");
//        cout << lp << " " << lsum << " " << lval << " " << llen << endl;
//        puts("rp, rsum, rval, rlen");
//        cout << rp << " " << rsum << " " << rval << " " << rlen << endl;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == (int)circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == (int)circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

//    freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
//    for (int i  = 1; i <= n; i++){
//        cout << son[i] << endl;
//    }
    Gocircle();
    for (int i = 1; i <= n; i++){
//        cout << ans[i] << (char)(i == n ? 10 : 32);
        printf("%I64d%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月14日, 下午7:12
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
__int64 ans[MAXN];

int Dfs2(int pos, __int64 &val, __int64 len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, __int64 val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    __int64 val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, __int64 val, int num, __int64 len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, __int64 val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    __int64 totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    __int64 llen = 0, rlen = 0;
    __int64 lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= circle.size();

    for (int i = 0; i < circle.size(); i++){
//        puts("lp, lsum, lval, llen");
//        printf("%d %d %d %d\n", lp, lsum, lval, llen);
//        puts("rp, rsum, rval, rlen");
//        printf("%d %d %d %d\n", rp, rsum, rval, rlen);
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[i].first ];
        rlen -= circle[i].second;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

//    freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
    Gocircle();
    for (int i = 1; i <= n; i++){
        printf("%I64d%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月14日, 下午7:12
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
long long ans[MAXN];

int Dfs2(int pos, long long &val, long long len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, long long val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    long long val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, long long val, int num, long long len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, long long val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    long long totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    long long llen = 0, rlen = 0;
    long long lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < (int)circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = (int)circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= (int)circle.size();

//    for (int i = 0; i < (int)circle.size(); i++)
//        printf("%d\n", circle[i].first);
    for (int i = 0; i < (int)circle.size(); i++){
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[(i + 1) % (int)circle.size()].first ];
        rlen -= circle[i].second;
//        puts("lp, lsum, lval, llen");
//        cout << lp << " " << lsum << " " << lval << " " << llen << endl;
//        puts("rp, rsum, rval, rlen");
//        cout << rp << " " << rsum << " " << rval << " " << rlen << endl;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == (int)circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == (int)circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

    freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
//    for (int i  = 1; i <= n; i++){
//        cout << son[i] << endl;
//    }
    Gocircle();
    for (int i = 1; i <= n; i++){
//        cout << ans[i] << (char)(i == n ? 10 : 32);
        printf("%lld%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月14日, 下午7:12
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
long long ans[MAXN];

int Dfs2(int pos, long long &val, long long len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, long long val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    long long val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, long long val, int num, long long len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, long long val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    long long totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    long long llen = 0, rlen = 0;
    long long lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < (int)circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = (int)circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= (int)circle.size();

//    for (int i = 0; i < (int)circle.size(); i++)
//        printf("%d\n", circle[i].first);
    for (int i = 0; i < (int)circle.size(); i++){
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[(i + 1) % (int)circle.size()].first ];
        rlen -= circle[i].second;
//        puts("lp, lsum, lval, llen");
//        cout << lp << " " << lsum << " " << lval << " " << llen << endl;
//        puts("rp, rsum, rval, rlen");
//        cout << rp << " " << rsum << " " << rval << " " << rlen << endl;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == (int)circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == (int)circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

 //   freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
//    for (int i  = 1; i <= n; i++){
//        cout << son[i] << endl;
//    }
    Gocircle();
    for (int i = 1; i <= n; i++){
//        cout << ans[i] << (char)(i == n ? 10 : 32);
        printf("%lld%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月14日, 下午7:12
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
__int64 ans[MAXN];

int Dfs2(int pos, __int64 &val, __int64 len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, __int64 val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    __int64 val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, __int64 val, int num, __int64 len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, __int64 val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    __int64 totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    __int64 llen = 0, rlen = 0;
    __int64 lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < (int)circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = (int)circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= (int)circle.size();

    for (int i = 0; i < (int)circle.size(); i++){
//        puts("lp, lsum, lval, llen");
//        printf("%d %d %d %d\n", lp, lsum, lval, llen);
//        puts("rp, rsum, rval, rlen");
//        printf("%d %d %d %d\n", rp, rsum, rval, rlen);
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[i].first ];
        rlen -= circle[i].second;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == (int)circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == (int)circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

//    freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
    Gocircle();
    for (int i = 1; i <= n; i++){
        printf("%I64d%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月14日, 下午7:12
 */

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 220000;
int n;

struct Edge{
    int e, v, wh;
    Edge(){};
    Edge(int a, int b, int c){e = a; v = b; wh = c;}
};

vector <Edge> v[MAXN];

int ins[MAXN];
int oncir[MAXN];
int used[MAXN];
vector < pair <int, int> > circle;

typedef vector<Edge>::iterator VEpoint;
typedef vector< pair<int, int> >::iterator VPpoint;

int Dfs(int pos, int val){

    circle.push_back( make_pair(pos, val));
    if (ins[pos] == 1)
        return 0;
    ins[pos] = 1;
    for (vector<Edge>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
        if (used[it->wh] == 1) continue;
        used[it->wh] = 1;
        if (Dfs(it->e, it->v) == 0) return 0;
    }
    circle.erase(circle.end() - 1);
    ins[pos] = 0;
    return 1;
}

int Find_Circle(){

    memset(ins, 0, sizeof(ins));
    memset(used, 0, sizeof(used));
    Dfs(1, 0);
    reverse(circle.begin(), circle.end());
    for (VPpoint it = circle.end() - 1; ; it--){
        if (it->first == circle[0].first){
            circle.erase(it, circle.end());
            break;
        }
    }
    for (VPpoint it = circle.begin(); it != circle.end(); it++)
        oncir[it->first] = 1;
    return 0;
}

int son[MAXN];
long long ans[MAXN];

int Dfs2(int pos, long long &val, long long len){

    son[pos]++;
    val += len;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        son[pos] += Dfs2(it->e, val, len + it->v);
    }
    ins[pos] = 0;
    return son[pos];
}

int Dfs3(int pos, long long val, int tot){

    ans[pos] = val;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (ins[it->e] == 1) continue;
        if (oncir[it->e] == 1) continue;
        Dfs3(it->e, val + (tot - son[it->e] - son[it->e]) * it->v, tot);
    }
    ins[pos] = 0;
    return 0;
}

int Cal(int pos){

    long long val = 0;
    Dfs2(pos, val, 0);
    Dfs3(pos, val, son[pos]);
    return 0;
}

int Calculate(){

    memset(ins, 0, sizeof(ins));
    for (int i = 1; i <= n; i++)
        if (oncir[i] == 1) Cal(i);
    return 0;
}

int Dfs4(int pos, long long val, int num, long long len){
    ans[pos] += val + len * num;
    ins[pos] = 1;
    for (VEpoint it = v[pos].begin(); it != v[pos].end(); it++){
        if (oncir[it->e] == 1) continue;
        if (ins[it->e] == 1) continue;
        Dfs4(it->e, val, num, len + it->v);
    }
    ins[pos] = 0;
    return 0;
}

int Ad(int pos, long long val, int num){
    Dfs4(pos, val, num, 0);
    return 0;
}

int Gocircle(){

    long long totlen = 0;
    int tot = 0;
    for (VPpoint it = circle.begin(); it != circle.end(); it++){
        tot += it->second;
        totlen += ans[it->first];
    }
    int lp = 0, rp = 0;
    long long llen = 0, rlen = 0;
    long long lval = 0, rval = 0;
    int lsum = 0, rsum = 0;
    for (int i = 0; i < (int)circle.size(); i++){
        rval += rlen * son[ circle[i].first ];
        rsum += son[ circle[i].first ];
        if ((rlen + circle[i].second) * 2 > tot){
            rp = i;
            break;
        }
        rlen += circle[i].second;
    }

    rsum -= son[ circle[0].first ];

    lp = rp + 1;

    for (int i = (int)circle.size() - 1; i >= lp; i--){
        llen += circle[i].second;
        lval += llen * son[ circle[i].first ];
        lsum += son[ circle[i].first ];
    }
    lp %= (int)circle.size();

//    for (int i = 0; i < (int)circle.size(); i++)
//        printf("%d\n", circle[i].first);
    for (int i = 0; i < (int)circle.size(); i++){
        Ad(circle[i].first, lval + rval + totlen - ans[circle[i].first], n - son[circle[i].first]);
        lsum += son[ circle[i].first ];
        lval += lsum * circle[i].second;
        llen += circle[i].second;
        rval -= rsum * circle[i].second;
        rsum -= son[ circle[(i + 1) % (int)circle.size()].first ];
        rlen -= circle[i].second;
//        puts("lp, lsum, lval, llen");
//        cout << lp << " " << lsum << " " << lval << " " << llen << endl;
//        puts("rp, rsum, rval, rlen");
//        cout << rp << " " << rsum << " " << rval << " " << rlen << endl;
        while ((circle[rp].second + rlen) * 2 <= tot){

            rlen += circle[rp].second;
            rp++;
            if(rp == (int)circle.size()) rp = 0;
            rval += rlen * son[ circle[rp].first ];
            rsum += son[ circle[rp].first ];

            lval -= llen * son[ circle[lp].first ];
            llen -= circle[lp].second;
            lsum -= son[ circle[lp].first ];
            lp ++;
            if (lp == (int)circle.size()) lp = 0;
        }
    }
    return 0;
}

int main() {

//    freopen("in", "r", stdin);
    memset(oncir, 0, sizeof(oncir));
    memset(ans, 0, sizeof(ans));
    memset(son, 0, sizeof(son));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a].push_back(Edge(b, c, i));
        v[b].push_back(Edge(a, c, i));
    }
    Find_Circle();
    Calculate();
//    for (int i  = 1; i <= n; i++){
//        cout << son[i] << endl;
//    }
    Gocircle();
    for (int i = 1; i <= n; i++){
//        cout << ans[i] << (char)(i == n ? 10 : 32);
        printf("%I64d%c", ans[i], i == n ? 10 : 32);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

vector<PII> e[200000];
long long sum[200000],rev[200000],jmp[200000],way[200000];
int pos[200000],cnt[200000],dot[200001];

void fwd_build(int x, int src){
    cnt[x]=1;
    pos[x]=pos[src];
    for(auto& r:e[x]){
        int y=r.first;
        if(~pos[y]) continue;
        fwd_build(y,x);
        cnt[x]+=cnt[y];
        sum[x]+=sum[y]+cnt[y]*r.second;
    }
}

void rev_build(int x, int src){
    for(auto& r:e[x]){
        int y=r.first;
        if(y==src || pos[y]!=pos[x]) continue;
        way[y]+=way[x]+r.second;
        rev[y]+=(cnt[pos[x]]-cnt[y])*1ll*r.second+rev[x]+sum[x]-sum[y]-cnt[y]*r.second;
        rev_build(y,x);
    }
}

int main(){
    int n,t=0,last=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        e[x-1].push_back({y-1,c});
        e[y-1].push_back({x-1,c});
    }
    vector<int> u;
    vector<PII> c;
    for(int i=0;i<n;i++){
        pos[i]=e[i].size();
        if(pos[i]==1) u.push_back(i);
    }
    for(size_t i=0;i<u.size();i++)
        for(auto y:e[u[i]])
            if(--pos[y.first]==1) u.push_back(y.first);
    for(int i=0;i<n;i++) pos[i]=pos[i]>=2?t=i:-1;
    do{
        size_t i;
        for(i=0;i<e[t].size();i++)
            if(~pos[e[t][i].first] && e[t][i].first!=last) break;
        c.push_back({t,e[t][i].second});
        last=t,t=e[t][i].first;
    }while(c[0].first!=t);
    for(int i=0;i<n;i++)
        if(pos[i]==i) fwd_build(i,i),rev_build(i,i);
    size_t go=0;
    long long all=0,tmp=0,grp=0;
    for(size_t i=0;i<c.size();i++){
        all+=c[i].second;
        dot[i+1]=dot[i]+cnt[c[i].first];
    }
    for(size_t i=c.size()-1;i;i--){
        tmp+=c[i].second;
        grp+=tmp*cnt[c[i].first];
    }
    for(size_t i=tmp=0;i<c.size();i++){
        int x=c[i].first;
        while((tmp+c[go].second)*2<=all){
            tmp+=c[go++].second;
            if(go==c.size()) go=0;
            grp+=(2*tmp-all)*cnt[c[go].first];
        }
        jmp[x]=grp;
        if(i==go){
            go=(go+1)%c.size();
            grp-=(all-c[i].second)*cnt[c[(i+1)%c.size()].first];
            grp+=c[i].second*(dot[c.size()]+0ll-cnt[c[(i+1)%c.size()].first]);
        }else{
            tmp-=c[i].second;
            if(go>=i){
                grp+=(dot[c.size()]-2*(dot[go+1]-dot[i+1]))*c[i].second;
            }else{
                grp+=(2*(dot[i+1]-dot[go+1])-dot[c.size()])*c[i].second;
            }
        }
    }
    long long gaz=0;
    for(int i=0;i<n;i++) if(pos[i]==i) gaz+=sum[i];
    for(int i=0;i<n;i++){
        long long ans=sum[i]+rev[i];
        ans+=jmp[pos[i]]+way[i]*(dot[c.size()]-cnt[pos[i]])+gaz-sum[pos[i]];
        printf("%I64d\n",ans);
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

vector<PII> e[200000];
long long sum[200000],rev[200000],jmp[200000];
int pos[200000],cnt[200000],dot[200001];

void fwd_build(int x, int src){
    cnt[x]=1;
    pos[x]=pos[src];
    for(auto& r:e[x]){
        int y=r.first;
        if(~pos[y]) continue;
        fwd_build(y,x);
        cnt[x]+=cnt[y];
        sum[x]+=sum[y]+cnt[y]*r.second;
    }
}

void rev_build(int x, int src){
    for(auto& r:e[x]){
        int y=r.first;
        if(y==src || pos[y]!=pos[x]) continue;
        rev[y]+=(cnt[pos[x]]-cnt[y])*1ll*r.second+rev[x];
        rev_build(y,x);
    }
}

int main(){
    int n,t=0,last=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        e[x-1].push_back({y-1,c});
        e[y-1].push_back({x-1,c});
    }
    vector<int> u;
    vector<PII> c;
    for(int i=0;i<n;i++){
        pos[i]=e[i].size();
        if(pos[i]==1) u.push_back(i);
    }
    for(size_t i=0;i<u.size();i++)
        for(auto y:e[u[i]])
            if(--pos[y.first]==1) u.push_back(y.first);
    for(int i=0;i<n;i++) pos[i]=pos[i]>=2?t=i:-1;
    do{
        size_t i;
        for(i=0;i<e[t].size();i++)
            if(~pos[e[t][i].first] && e[t][i].first!=last) break;
        c.push_back({t,e[t][i].second});
        last=t,t=e[t][i].first;
    }while(c[0].first!=t);
    for(int i=0;i<n;i++)
        if(~pos[i]) fwd_build(i,i),rev_build(i,i);
    size_t go=0;
    long long all=0,tmp=0,grp=0;
    for(size_t i=0;i<c.size();i++){
        all+=c[i].second;
        dot[i+1]=dot[i]+cnt[c[i].first];
    }
    for(size_t i=c.size()-1;i;i--){
        tmp+=c[i].second;
        grp+=tmp*cnt[c[i].first];
    }
    for(size_t i=tmp=0;i<c.size();i++){
        int x=c[i].first;
        while((tmp+c[go].second)*2<=all){
            tmp+=c[go++].second;
            if(go==c.size()) go=0;
            grp+=(2*tmp-all)*cnt[c[go].first];
        }
        jmp[x]=grp;
        if(i==go){
            go=(go+1)%c.size();
        }else{
            tmp-=c[i].second;
            if(go>=i){
                grp+=(dot[c.size()]-2*(dot[go+1]-dot[i+1]))*c[i].second;
            }else{
                grp+=(2*(dot[i+1]-dot[go+1])-dot[c.size()])*c[i].second;
            }
        }
    }
    long long gaz=0;
    for(int i=0;i<n;i++) gaz+=sum[i];
    for(int i=0;i<n;i++){
        long long ans=sum[i]+rev[i];
        ans+=jmp[pos[i]]+gaz-sum[pos[i]];
        printf("%I64d ",ans);
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

vector<PII> e[200000];
long long sum[200000],rev[200000],jmp[200000],way[200000];
int pos[200000],cnt[200000],dot[200001];

void fwd_build(int x, int src){
    cnt[x]=1;
    pos[x]=pos[src];
    for(auto& r:e[x]){
        int y=r.first;
        if(~pos[y]) continue;
        fwd_build(y,x);
        cnt[x]+=cnt[y];
        sum[x]+=sum[y]+cnt[y]*r.second;
    }
}

void rev_build(int x, int src){
    for(auto& r:e[x]){
        int y=r.first;
        if(y==src || pos[y]!=pos[x]) continue;
        way[y]+=way[x]+r.second;
        rev[y]+=(cnt[pos[x]]-cnt[y])*1ll*r.second+rev[x];
        rev_build(y,x);
    }
}

int main(){
    int n,t=0,last=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        e[x-1].push_back({y-1,c});
        e[y-1].push_back({x-1,c});
    }
    vector<int> u;
    vector<PII> c;
    for(int i=0;i<n;i++){
        pos[i]=e[i].size();
        if(pos[i]==1) u.push_back(i);
    }
    for(size_t i=0;i<u.size();i++)
        for(auto y:e[u[i]])
            if(--pos[y.first]==1) u.push_back(y.first);
    for(int i=0;i<n;i++) pos[i]=pos[i]>=2?t=i:-1;
    do{
        size_t i;
        for(i=0;i<e[t].size();i++)
            if(~pos[e[t][i].first] && e[t][i].first!=last) break;
        c.push_back({t,e[t][i].second});
        last=t,t=e[t][i].first;
    }while(c[0].first!=t);
    for(int i=0;i<n;i++)
        if(pos[i]==i) fwd_build(i,i),rev_build(i,i);
    size_t go=0;
    long long all=0,tmp=0,grp=0;
    for(size_t i=0;i<c.size();i++){
        all+=c[i].second;
        dot[i+1]=dot[i]+cnt[c[i].first];
    }
    for(size_t i=c.size()-1;i;i--){
        tmp+=c[i].second;
        grp+=tmp*cnt[c[i].first];
    }
    for(size_t i=tmp=0;i<c.size();i++){
        int x=c[i].first;
        while((tmp+c[go].second)*2<=all){
            tmp+=c[go++].second;
            if(go==c.size()) go=0;
            grp+=(2*tmp-all)*cnt[c[go].first];
        }
        jmp[x]=grp;
        if(i==go){
            go=(go+1)%c.size();
            grp-=(all-c[i].second)*cnt[c[(i+1)%c.size()].first];
            grp+=c[i].second*(dot[c.size()]+0ll-cnt[c[(i+1)%c.size()].first]);
        }else{
            tmp-=c[i].second;
            if(go>=i){
                grp+=(dot[c.size()]-2*(dot[go+1]-dot[i+1]))*c[i].second;
            }else{
                grp+=(2*(dot[i+1]-dot[go+1])-dot[c.size()])*c[i].second;
            }
        }
    }
    long long gaz=0;
    for(int i=0;i<n;i++) if(pos[i]==i) gaz+=sum[i];
    for(int i=0;i<n;i++){
        long long ans=sum[i]+rev[i];
        ans+=jmp[pos[i]]+way[i]*(dot[c.size()]-cnt[pos[i]])+gaz-sum[pos[i]];
        printf("%I64d\n",ans);
    }
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

vector<PII> e[200000];
long long sum[200000],rev[200000],jmp[200000],way[200000];
int pos[200000],cnt[200000],dot[200001];

void fwd_build(int x, int src){
    cnt[x]=1;
    pos[x]=pos[src];
    for(auto& r:e[x]){
        int y=r.first;
        if(~pos[y]) continue;
        fwd_build(y,x);
        cnt[x]+=cnt[y];
        sum[x]+=sum[y]+cnt[y]*r.second;
    }
}

void rev_build(int x, int src){
    for(auto& r:e[x]){
        int y=r.first;
        if(y==src || pos[y]!=pos[x]) continue;
        way[y]+=way[x]+r.second;
        rev[y]+=(cnt[pos[x]]-cnt[y])*1ll*r.second+rev[x];
        rev_build(y,x);
    }
}

int main(){
    int n,t=0,last=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        e[x-1].push_back({y-1,c});
        e[y-1].push_back({x-1,c});
    }
    vector<int> u;
    vector<PII> c;
    for(int i=0;i<n;i++){
        pos[i]=e[i].size();
        if(pos[i]==1) u.push_back(i);
    }
    for(size_t i=0;i<u.size();i++)
        for(auto y:e[u[i]])
            if(--pos[y.first]==1) u.push_back(y.first);
    for(int i=0;i<n;i++) pos[i]=pos[i]>=2?t=i:-1;
    do{
        size_t i;
        for(i=0;i<e[t].size();i++)
            if(~pos[e[t][i].first] && e[t][i].first!=last) break;
        c.push_back({t,e[t][i].second});
        last=t,t=e[t][i].first;
    }while(c[0].first!=t);
    for(int i=0;i<n;i++)
        if(pos[i]==i) fwd_build(i,i),rev_build(i,i);
    size_t go=0;
    long long all=0,tmp=0,grp=0;
    for(size_t i=0;i<c.size();i++){
        all+=c[i].second;
        dot[i+1]=dot[i]+cnt[c[i].first];
    }
    for(size_t i=c.size()-1;i;i--){
        tmp+=c[i].second;
        grp+=tmp*cnt[c[i].first];
    }
    for(size_t i=tmp=0;i<c.size();i++){
        int x=c[i].first;
        while((tmp+c[go].second)*2<=all){
            tmp+=c[go++].second;
            if(go==c.size()) go=0;
            grp+=(2*tmp-all)*cnt[c[go].first];
        }
        jmp[x]=grp;
        if(i==go){
            go=(go+1)%c.size();
            grp-=(all-c[i].second)*cnt[c[(i+1)%c.size()].first];
            grp+=c[i].second*(dot[c.size()]+0ll-cnt[c[(i+1)%c.size()].first]);
        }else{
            tmp-=c[i].second;
            if(go>=i){
                grp+=(dot[c.size()]-2*(dot[go+1]-dot[i+1]))*c[i].second;
            }else{
                grp+=(2*(dot[i+1]-dot[go+1])-dot[c.size()])*c[i].second;
            }
        }
    }
    long long gaz=0;
    for(int i=0;i<n;i++) gaz+=sum[i];
    for(int i=0;i<n;i++){
        long long ans=sum[i]+rev[i];
        ans+=jmp[pos[i]]+way[i]*(dot[c.size()]-cnt[pos[i]])+gaz-sum[pos[i]];
        printf("%I64d ",ans);
    }
}


#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
vector<pair<int, int> > V[200002];
vector<pair<int, int> > st, cycle;
bool is[200002], incycle[200002];
int C[200002], W[200002], distn[200002], D[200002];
int root[200002], cost[200002];
int S[600002], R[600002];

bool foundCycle;
void findCycle(int x, int tat)
{
    is[x] = true;
    for (auto it : V[x])
        if (!is[it.first])
        {
            st.push_back(make_pair(it.first, it.second));
            findCycle(it.first, x);
            st.pop_back();

            if (foundCycle) break;
        }
        else if (it.first != tat)
        {
            foundCycle = true;

            cycle.push_back(make_pair(it.first, it.second));
            while (true)
            {
                if (st.back().first == it.first) break;
                cycle.push_back(st.back());
                incycle[st.back().first] = true;
                st.pop_back();
            }

            break;
        }
}
void preCalc(int x)
{
    is[x] = true;

    W[x] = 1;
    C[x] = 0;

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            distn[it.first] = distn[x] + it.second;
            root[it.first] = root[x];
            preCalc(it.first);
            W[x] += W[it.first];
            C[x] += C[it.first] + it.second * W[it.first];
        }
}
void postCalc(int x)
{
    is[x] = true;

    D[x] = C[x];

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            int oldC = C[it.first];
            C[it.first] = C[x] - W[it.first] * it.second + (W[x] - W[it.first]) * it.second;
            postCalc(it.first);
            C[it.first] = oldC;
        }
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> N;
    for (int i = 1, nod1, nod2, cost; i <= N; ++i)
    {
        cin >> nod1 >> nod2 >> cost;
        V[nod1].push_back(make_pair(nod2, cost));
        V[nod2].push_back(make_pair(nod1, cost));
    }

    st.push_back(make_pair(1, 0));
    findCycle(1, 0);
    st.clear();

    int sumroots = 0;
    for (auto it : cycle)
    {
        memset(S, 0, sizeof(S));
        root[it.first] = it.first;
        preCalc(it.first);
        memset(S, 0, sizeof(S));
        postCalc(it.first);

        sumroots += D[it.first];
    }

    int M = cycle.size();
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);

    S[0] = W[cycle[0].first];
    R[0] = cycle[0].second;
    for (int i = 1; i < int(cycle.size()); ++i)
    {
        S[i] = S[i - 1] + W[cycle[i].first];
        R[i] = R[i - 1] + cycle[i].second;
    }

    int lim1 = 1, lim2 = M, costnow = 0;
    for (int i = 1; i < M; ++i)
        costnow += W[cycle[i].first] * (R[M - 1] - R[i - 1]);

    for (int i = M; i < 2 * M; ++i)
    {
        while (lim2 < i || (lim1 < i && W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]) - W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]) <= 0))
        {
            costnow -= W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]);
            costnow += W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]);
            ++lim1;
            ++lim2;
        }

        cost[cycle[i].first] = costnow;

        costnow += cycle[i].second * (S[i] - S[lim1 - 1]);
        costnow -= cycle[i].second * (S[lim2] - S[i]);
    }

    for (int i = 1; i <= N; ++i)
    {
        int result = D[i];
        result += sumroots - D[root[i]];
        result += distn[i] * (N - W[root[i]]);
        result += cost[root[i]];

        cout << result << ' ';
    }
    cout << '\n';
}


#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
vector<pair<int, int> > V[200002];
vector<pair<int, int> > st, cycle;
bool is[200002], incycle[200002];
int W[200002], distn[200002];
long long C[200002], D[200002];
int root[200002];
long long cost[200002];
long long S[600002], R[600002];

bool foundCycle;
void findCycle(int x, int tat)
{
    is[x] = true;
    for (auto it : V[x])
        if (!is[it.first])
        {
            st.push_back(make_pair(it.first, it.second));
            findCycle(it.first, x);
            st.pop_back();

            if (foundCycle) break;
        }
        else if (it.first != tat)
        {
            foundCycle = true;

            cycle.push_back(make_pair(it.first, it.second));
            incycle[it.first] = true;
            while (true)
            {
                if (st.back().first == it.first) break;
                cycle.push_back(st.back());
                incycle[st.back().first] = true;
                st.pop_back();
            }

            break;
        }
}
void preCalc(int x)
{
    is[x] = true;

    W[x] = 1;
    C[x] = 0;

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            distn[it.first] = distn[x] + it.second;
            root[it.first] = root[x];
            preCalc(it.first);
            W[x] += W[it.first];
            C[x] += C[it.first] + 1LL * it.second * W[it.first];
        }
}
void postCalc(int x)
{
    is[x] = true;

    D[x] = C[x];

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            int oldC = C[it.first];
            C[it.first] = C[x] - 1LL * W[it.first] * it.second + 1LL * (W[root[it.first]] - W[it.first]) * it.second;
            postCalc(it.first);
            C[it.first] = oldC;
        }
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> N;
    for (int i = 1, nod1, nod2, cost; i <= N; ++i)
    {
        cin >> nod1 >> nod2 >> cost;
        V[nod1].push_back(make_pair(nod2, cost));
        V[nod2].push_back(make_pair(nod1, cost));
    }

    st.push_back(make_pair(1, 0));
    findCycle(1, 0);
    st.clear();

    int sumroots = 0;
    for (auto it : cycle)
    {
        memset(is, 0, sizeof(is));
        root[it.first] = it.first;
        preCalc(it.first);
        memset(is, 0, sizeof(is));
        postCalc(it.first);

        sumroots += D[it.first];
    }

    int M = cycle.size();
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);

    S[0] = W[cycle[0].first];
    R[0] = cycle[0].second;
    for (int i = 1; i < int(cycle.size()); ++i)
    {
        S[i] = S[i - 1] + W[cycle[i].first];
        R[i] = R[i - 1] + cycle[i].second;
    }

    int lim1 = 1, lim2 = M;
    long long costnow = 0;
    for (int i = 1; i < M; ++i)
        costnow += W[cycle[i].first] * (R[M - 1] - R[i - 1]);

    for (int i = M; i < 2 * M; ++i)
    {
        while (lim2 < i || (lim1 < i && 1LL * W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]) - 1LL * W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]) <= 0))
        {
            costnow -= 1LL * W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]);
            costnow += 1LL * W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]);
            ++lim1;
            ++lim2;
        }

        cost[cycle[i].first] = costnow;

        costnow += 1LL * cycle[i].second * (S[i] - S[lim1 - 1]);
        costnow -= 1LL * cycle[i].second * (S[lim2] - S[i]);
    }

    for (int i = 1; i <= N; ++i)
    {
        long long result = D[i];
        result += sumroots - D[root[i]];
        result += 1LL * distn[i] * (N - W[root[i]]);
        result += cost[root[i]];

        cout << result << ' ';
    }
    cout << '\n';
}


#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
vector<pair<int, int> > V[200002];
vector<pair<int, int> > st, cycle;
bool is[200002], incycle[200002];
int C[200002], W[200002], distn[200002], D[200002];
int root[200002], cost[200002];
int S[600002], R[600002];

bool foundCycle;
void findCycle(int x, int tat)
{
    is[x] = true;
    for (auto it : V[x])
        if (!is[it.first])
        {
            st.push_back(make_pair(it.first, it.second));
            findCycle(it.first, x);
            st.pop_back();

            if (foundCycle) break;
        }
        else if (it.first != tat)
        {
            foundCycle = true;

            cycle.push_back(make_pair(it.first, it.second));
            incycle[it.first] = true;
            while (true)
            {
                if (st.back().first == it.first) break;
                cycle.push_back(st.back());
                incycle[st.back().first] = true;
                st.pop_back();
            }

            break;
        }
}
void preCalc(int x)
{
    is[x] = true;

    W[x] = 1;
    C[x] = 0;

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            distn[it.first] = distn[x] + it.second;
            root[it.first] = root[x];
            preCalc(it.first);
            W[x] += W[it.first];
            C[x] += C[it.first] + it.second * W[it.first];
        }
}
void postCalc(int x)
{
    is[x] = true;

    D[x] = C[x];

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            int oldC = C[it.first];
            C[it.first] = C[x] - W[it.first] * it.second + (W[root[it.first]] - W[it.first]) * it.second;
            postCalc(it.first);
            C[it.first] = oldC;
        }
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> N;
    for (int i = 1, nod1, nod2, cost; i <= N; ++i)
    {
        cin >> nod1 >> nod2 >> cost;
        V[nod1].push_back(make_pair(nod2, cost));
        V[nod2].push_back(make_pair(nod1, cost));
    }

    st.push_back(make_pair(1, 0));
    findCycle(1, 0);
    st.clear();

    int sumroots = 0;
    for (auto it : cycle)
    {
        memset(is, 0, sizeof(is));
        root[it.first] = it.first;
        preCalc(it.first);
        memset(is, 0, sizeof(is));
        postCalc(it.first);

        sumroots += D[it.first];
    }

    int M = cycle.size();
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);

    S[0] = W[cycle[0].first];
    R[0] = cycle[0].second;
    for (int i = 1; i < int(cycle.size()); ++i)
    {
        S[i] = S[i - 1] + W[cycle[i].first];
        R[i] = R[i - 1] + cycle[i].second;
    }

    int lim1 = 1, lim2 = M, costnow = 0;
    for (int i = 1; i < M; ++i)
        costnow += W[cycle[i].first] * (R[M - 1] - R[i - 1]);

    for (int i = M; i < 2 * M; ++i)
    {
        while (lim2 < i || (lim1 < i && W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]) - W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]) <= 0))
        {
            costnow -= W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]);
            costnow += W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]);
            ++lim1;
            ++lim2;
        }

        cost[cycle[i].first] = costnow;

        costnow += cycle[i].second * (S[i] - S[lim1 - 1]);
        costnow -= cycle[i].second * (S[lim2] - S[i]);
    }

    for (int i = 1; i <= N; ++i)
    {
        int result = D[i];
        result += sumroots - D[root[i]];
        result += distn[i] * (N - W[root[i]]);
        result += cost[root[i]];

        cout << result << ' ';
    }
    cout << '\n';
}


#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
vector<pair<int, int> > V[200002];
vector<pair<int, int> > st, cycle;
bool is[200002], incycle[200002];
int C[200002], W[200002], distn[200002], D[200002];
int root[200002], cost[200002];
int S[600002], R[600002];

bool foundCycle;
void findCycle(int x, int tat)
{
    is[x] = true;
    for (auto it : V[x])
        if (!is[it.first])
        {
            st.push_back(make_pair(it.first, it.second));
            findCycle(it.first, x);
            st.pop_back();

            if (foundCycle) break;
        }
        else if (it.first != tat)
        {
            foundCycle = true;

            cycle.push_back(make_pair(it.first, it.second));
            incycle[it.first] = true;
            while (true)
            {
                if (st.back().first == it.first) break;
                cycle.push_back(st.back());
                incycle[st.back().first] = true;
                st.pop_back();
            }

            break;
        }
}
void preCalc(int x)
{
    is[x] = true;

    W[x] = 1;
    C[x] = 0;

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            distn[it.first] = distn[x] + it.second;
            root[it.first] = root[x];
            preCalc(it.first);
            W[x] += W[it.first];
            C[x] += C[it.first] + it.second * W[it.first];
        }
}
void postCalc(int x)
{
    is[x] = true;

    D[x] = C[x];

    for (auto it : V[x])
        if (!is[it.first] && !incycle[it.first])
        {
            int oldC = C[it.first];
            C[it.first] = C[x] - W[it.first] * it.second + (W[x] - W[it.first]) * it.second;
            postCalc(it.first);
            C[it.first] = oldC;
        }
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> N;
    for (int i = 1, nod1, nod2, cost; i <= N; ++i)
    {
        cin >> nod1 >> nod2 >> cost;
        V[nod1].push_back(make_pair(nod2, cost));
        V[nod2].push_back(make_pair(nod1, cost));
    }

    st.push_back(make_pair(1, 0));
    findCycle(1, 0);
    st.clear();

    int sumroots = 0;
    for (auto it : cycle)
    {
        memset(is, 0, sizeof(is));
        root[it.first] = it.first;
        preCalc(it.first);
        memset(is, 0, sizeof(is));
        postCalc(it.first);

        sumroots += D[it.first];
    }

    int M = cycle.size();
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);
    for (int i = 0; i < M; ++i)
        cycle.push_back(cycle[i]);

    S[0] = W[cycle[0].first];
    R[0] = cycle[0].second;
    for (int i = 1; i < int(cycle.size()); ++i)
    {
        S[i] = S[i - 1] + W[cycle[i].first];
        R[i] = R[i - 1] + cycle[i].second;
    }

    int lim1 = 1, lim2 = M, costnow = 0;
    for (int i = 1; i < M; ++i)
        costnow += W[cycle[i].first] * (R[M - 1] - R[i - 1]);

    for (int i = M; i < 2 * M; ++i)
    {
        while (lim2 < i || (lim1 < i && W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]) - W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]) <= 0))
        {
            costnow -= W[cycle[lim1].first] * (R[i - 1] - R[lim1 - 1]);
            costnow += W[cycle[lim2 + 1].first] * (R[lim2] - R[i - 1]);
            ++lim1;
            ++lim2;
        }

        cost[cycle[i].first] = costnow;

        costnow += cycle[i].second * (S[i] - S[lim1 - 1]);
        costnow -= cycle[i].second * (S[lim2] - S[i]);
    }

    for (int i = 1; i <= N; ++i)
    {
        int result = D[i];
        result += sumroots - D[root[i]];
        result += distn[i] * (N - W[root[i]]);
        result += cost[root[i]];

        cout << result << ' ';
    }
    cout << '\n';
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;

public class G {

	static StreamTokenizer st;
	static class Adge {
		int id,dis;
		public Adge(int id, int dis) {
			this.id = id;
			this.dis = dis;
		}
	}
	static ArrayList<Adge>[]ages;
	static int[]color, p, cnt;
	static long[]d0,d;
	static boolean[]in_circle;
	static int cur_root, n;
	public static void main(String[] args) throws IOException{
		st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = nextInt();
		ages = new ArrayList[n+1];
		for (int i = 1; i <= n; i++) {
			ages[i] = new ArrayList<Adge>();
		}
		for (int i = 1; i <= n; i++) {
			int a = nextInt();
			int b = nextInt();
			int t = nextInt();
			ages[a].add(new Adge(b, t));
			ages[b].add(new Adge(a, t));
		}
		color = new int[n+1];
		p = new int[n+1];
		in_circle = new boolean[n+1];
		dfs(1);
		cnt = new int[n+1];
		d0 = new long[n+1];
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				cur_root = i;
				dfs2(i, 0, 0);
			}
		}
		d = new long[n+1];
		for (int i = 1; i <= n; i++) {
			d[i] = d0[i];
		}
		int[]dis_p = new int[n+1];
		int first = 0, last = 0;
		long length_circle = 0;
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				first = i;
				for (Adge to : ages[i]) {
					if (to.id==p[i]) {
						dis_p[i] = to.dis;
						length_circle += to.dis;
						break;
					}
				}
			}
		}
		long s = 0;
		last = first;
		long cur = 0;
		int cur_cnt = 0;
		boolean f = true;
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			while (s+dis_p[last] <= length_circle/2) {
				s += dis_p[last];
				cur += s*cnt[last];
				cur_cnt += cnt[last];
				last = p[last];
			}
			d[i] += cur;
			cur -= dis_p[i]*cur_cnt;
			cur_cnt -= cnt[i];
			s -= dis_p[i];
		}
		f = true;
		int[]p_rev = new int[n+1], dis_p_rev = new int[n+1];
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			p_rev[p[i]] = i;
			dis_p_rev[p[i]] = dis_p[i];
		}
		s = 0;
		last = first;
		cur = 0;
		cur_cnt = 0;
		f = true;
		for (int i = first; i != first || f; i = p_rev[i]) {
			f = false;
			while (s+dis_p_rev[last] < length_circle/2) {
				s += dis_p_rev[last];
				cur += s*cnt[last];
				cur_cnt += cnt[last];
				last = p_rev[last];
			}
			d[i] += cur;
			cur -= dis_p_rev[i]*cur_cnt;
			cur_cnt -= cnt[i];
			s -= dis_p_rev[i];
		}
		for (int i = 1; i <= n; i++) {
			if (in_circle[i])
				dfs3(i, 0);
		}
		for (int i = 1; i <= n; i++) {
			pw.print(d[i]+" ");
		}
		pw.close();
	}

	private static void dfs3(int v, int p) {
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			d[to.id] = d[v]+(n-2*cnt[to.id])*to.dis;
			dfs3(to.id, v);
		}
	}

	private static void dfs2(int v, int p, int dis_to_root) {
		d0[cur_root] += dis_to_root;
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			dfs2(to.id, v, dis_to_root+to.dis);
			cnt[v] += cnt[to.id];
		}
		cnt[v]++;
	}

	private static void dfs(int v) {
		color[v] = 1;
		for (Adge to : ages[v]) {
			if (to.id==p[v])
				continue;
			if (color[to.id]==0) {
				p[to.id] = v;
				dfs(to.id);
			}
			else if (color[to.id]==1) {
				int cur = v;
				while (true) {
					in_circle[cur] = true;
					if (cur==to.id)
						break;
					cur = p[cur];
				}
				p[to.id] = v;
			}
		}
		color[v] = 2;
	}

	private static int nextInt() throws IOException{
		st.nextToken();
		return (int) st.nval;
	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;

public class G {

	static StreamTokenizer st;
	static class Adge {
		int id,dis;
		public Adge(int id, int dis) {
			this.id = id;
			this.dis = dis;
		}
	}
	static ArrayList<Adge>[]ages;
	static int[]color, p, cnt;
	static long[]d0,d;
	static boolean[]in_circle;
	static int cur_root, n;
	public static void main(String[] args) throws IOException{
		st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = nextInt();
		ages = new ArrayList[n+1];
		for (int i = 1; i <= n; i++) {
			ages[i] = new ArrayList<Adge>();
		}
		for (int i = 1; i <= n; i++) {
			int a = nextInt();
			int b = nextInt();
			int t = nextInt();
			ages[a].add(new Adge(b, t));
			ages[b].add(new Adge(a, t));
		}
		color = new int[n+1];
		p = new int[n+1];
		in_circle = new boolean[n+1];
		dfs(1);
		cnt = new int[n+1];
		d0 = new long[n+1];
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				cur_root = i;
				dfs2(i, 0, 0);
			}
		}
		d = new long[n+1];
		for (int i = 1; i <= n; i++) {
			d[i] = d0[i];
		}
		int[]dis_p = new int[n+1];
		int first = 0, last = 0;
		long length_circle = 0;
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				first = i;
				for (Adge to : ages[i]) {
					if (to.id==p[i]) {
						dis_p[i] = to.dis;
						length_circle += to.dis;
						break;
					}
				}
			}
		}
		long s = 0;
		last = first;
		long cur = 0;
		int cur_cnt = 0;
		boolean f = true;
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			while (s+dis_p[last] <= length_circle/2) {
				s += dis_p[last];
				last = p[last];
				cur += d0[last]+s*cnt[last];
				cur_cnt += cnt[last];
			}
			d[i] += cur;
			cur -= d0[p[i]]+dis_p[i]*cur_cnt;
			cur_cnt -= cnt[p[i]];
			s -= dis_p[i];
		}
		f = true;
		int[]p_rev = new int[n+1], dis_p_rev = new int[n+1];
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			p_rev[p[i]] = i;
			dis_p_rev[p[i]] = dis_p[i];
		}
		s = 0;
		last = first;
		cur = 0;
		cur_cnt = 0;
		f = true;
		for (int i = first; i != first || f; i = p_rev[i]) {
			f = false;
			while (s+dis_p_rev[last] < length_circle/2) {
				s += dis_p_rev[last];
				last = p_rev[last];
				cur += d0[last]+s*cnt[last];
				cur_cnt += cnt[last];
			}
			d[i] += cur;
			cur -= d0[p_rev[i]]+dis_p_rev[i]*cur_cnt;
			cur_cnt -= cnt[p_rev[i]];
			s -= dis_p_rev[i];
		}
		for (int i = 1; i <= n; i++) {
			if (in_circle[i])
				dfs3(i, 0);
		}
		for (int i = 1; i <= n; i++) {
			pw.print(d[i]+" ");
		}
		pw.close();
	}

	private static void dfs3(int v, int p) {
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			d[to.id] = d[v]+(n-2*cnt[to.id])*to.dis;
			dfs3(to.id, v);
		}
	}

	private static void dfs2(int v, int p, int dis_to_root) {
		d0[cur_root] += dis_to_root;
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			dfs2(to.id, v, dis_to_root+to.dis);
			cnt[v] += cnt[to.id];
		}
		cnt[v]++;
	}

	private static void dfs(int v) {
		color[v] = 1;
		for (Adge to : ages[v]) {
			if (to.id==p[v])
				continue;
			if (color[to.id]==0) {
				p[to.id] = v;
				dfs(to.id);
			}
			else if (color[to.id]==1) {
				int cur = v;
				while (true) {
					in_circle[cur] = true;
					if (cur==to.id)
						break;
					cur = p[cur];
				}
				p[to.id] = v;
			}
		}
		color[v] = 2;
	}

	private static int nextInt() throws IOException{
		st.nextToken();
		return (int) st.nval;
	}

}
/*
8
1 2 2
2 3 3
3 4 4
4 1 1
4 8 4
4 7 5
2 5 2
2 6 2
*/


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;

public class G {

	static StreamTokenizer st;
	static class Adge {
		int id,dis;
		public Adge(int id, int dis) {
			this.id = id;
			this.dis = dis;
		}
	}
	static ArrayList<Adge>[]ages;
	static int[]color, p, cnt;
	static long[]d0,d;
	static boolean[]in_circle;
	static int cur_root, n;
	public static void main(String[] args) throws IOException{
		st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = nextInt();
		ages = new ArrayList[n+1];
		for (int i = 1; i <= n; i++) {
			ages[i] = new ArrayList<Adge>();
		}
		for (int i = 1; i <= n; i++) {
			int a = nextInt();
			int b = nextInt();
			int t = nextInt();
			ages[a].add(new Adge(b, t));
			ages[b].add(new Adge(a, t));
		}
		color = new int[n+1];
		p = new int[n+1];
		in_circle = new boolean[n+1];
		dfs(1);
		cnt = new int[n+1];
		d0 = new long[n+1];
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				cur_root = i;
				dfs2(i, 0, 0);
			}
		}
		d = new long[n+1];
		for (int i = 1; i <= n; i++) {
			d[i] = d0[i];
		}
		int[]dis_p = new int[n+1];
		int first = 0, last = 0;
		long length_circle = 0;
		for (int i = 1; i <= n; i++) {
			if (in_circle[i]) {
				first = i;
				for (Adge to : ages[i]) {
					if (to.id==p[i]) {
						dis_p[i] = to.dis;
						length_circle += to.dis;
						break;
					}
				}
			}
		}
		long s = 0;
		last = first;
		long cur = 0;
		int cur_cnt = 0;
		boolean f = true;
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			while (s+dis_p[last] <= length_circle/2) {
				s += dis_p[last];
				last = p[last];
				cur += d0[last]+s*cnt[last];
				cur_cnt += cnt[last];
			}
			d[i] += cur;
			cur -= d0[p[i]]+dis_p[i]*cur_cnt;
			cur_cnt -= cnt[p[i]];
			s -= dis_p[i];
		}
		f = true;
		int[]p_rev = new int[n+1], dis_p_rev = new int[n+1];
		for (int i = first; i != first || f; i = p[i]) {
			f = false;
			p_rev[p[i]] = i;
			dis_p_rev[p[i]] = dis_p[i];
		}
		s = 0;
		last = first;
		cur = 0;
		cur_cnt = 0;
		f = true;
		for (int i = first; i != first || f; i = p_rev[i]) {
			f = false;
			while (s+dis_p_rev[last] < (length_circle % 2==0 ? length_circle/2 : length_circle/2+1)) {
				s += dis_p_rev[last];
				last = p_rev[last];
				cur += d0[last]+s*cnt[last];
				cur_cnt += cnt[last];
			}
			d[i] += cur;
			cur -= d0[p_rev[i]]+dis_p_rev[i]*cur_cnt;
			cur_cnt -= cnt[p_rev[i]];
			s -= dis_p_rev[i];
		}
		for (int i = 1; i <= n; i++) {
			if (in_circle[i])
				dfs3(i, 0);
		}
		for (int i = 1; i <= n; i++) {
			pw.print(d[i]+" ");
		}
		pw.close();
	}

	private static void dfs3(int v, int p) {
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			d[to.id] = d[v]+(n-2*cnt[to.id])*to.dis;
			dfs3(to.id, v);
		}
	}

	private static void dfs2(int v, int p, int dis_to_root) {
		d0[cur_root] += dis_to_root;
		for (Adge to : ages[v]) {
			if (to.id==p || in_circle[to.id])
				continue;
			dfs2(to.id, v, dis_to_root+to.dis);
			cnt[v] += cnt[to.id];
		}
		cnt[v]++;
	}

	private static void dfs(int v) {
		color[v] = 1;
		for (Adge to : ages[v]) {
			if (to.id==p[v])
				continue;
			if (color[to.id]==0) {
				p[to.id] = v;
				dfs(to.id);
			}
			else if (color[to.id]==1) {
				int cur = v;
				while (true) {
					in_circle[cur] = true;
					if (cur==to.id)
						break;
					cur = p[cur];
				}
				p[to.id] = v;
			}
		}
		color[v] = 2;
	}

	private static int nextInt() throws IOException{
		st.nextToken();
		return (int) st.nval;
	}

}
/*
8
1 2 2
2 3 3
3 4 4
4 1 1
4 8 4
4 7 5
2 5 2
2 6 2
*/