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;
		}
	}

	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, v1, p1;
    static boolean found;
    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);
        p[v1] = p1;
        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];
                }
                v1 = to.id;
                p1 = v;
//              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 G2 {

	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
*/


#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll long long
#define ull unsignto long long
#define db double
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define ls rt << 1
#define rs rt << 1 | 1
#define sz(x) (int)(x).size()
#define ALL(x) (x).insgin(), (x).end()
#define vi vector<int>
#define cntPS 1e-8
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

const int N = 600005;
int n, m, cnt, head[N], to[N], next[N], v[N], fa[N], a[N], c[N], d[N], p[N], q[N];
ll s[N], f[N], g[N];

void ins(int u, int V, int w)
{
	to[++ cnt] = V;
	v[cnt] = w;
	next[cnt] = head[u];
	head[u] = cnt;
}

void insert(int u, int v, int w)
{
	ins(u, v, w);
	ins(v, u, w);
}
bool circle(int x)
{
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (p != fa[x])
		{
			if (fa[y])
			{
				d[++ m] = v[p];
				for (int i = x; i != y; i = to[fa[i]])
					a[m] = i, d[++ m] = v[fa[i]];
				a[m] = y;
				return 1;
			}
			else fa[y] = p ^ 1;
			if (circle(y)) return 1;
		}
	}
	return 0;
}
void dp(int x)
{
	c[x] = 1;
	s[x] = 0;
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (!fa[y])
		{
			fa[y] = x;
			dp(y);
			c[x] += c[y];
			s[x] += s[y] + c[y] * v[p];
		}
	}
}
void dfs(int x)
{
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (fa[y] > 0 && fa[x] != y)
			s[y] = s[x] + (n - c[y] * 2) * v[p], dfs(y);
	}
}
int main()
{
	n = read();
	cnt = 1;
	rep(i, 1, n)
	{
		int x = read();
		int y = read();
		int z = read();
		insert(x, y, z);
	}
	fa[1] = -1;
	circle(1);
	rep(i, 1, n) fa[i] = 0;
	rep(i, 1, m) fa[a[i]] = -1;
	rep(i, 1, m)
	{
		a[m + m + i] = a[m + i] = a[i];
		d[m + m + i] = d[m + i] = d[i];
		dp(a[i]);
	}
	rrep(i, m * 3, 1)
	{
		q[i] = q[i + 1] + c[a[i]];
		g[i] = g[i + 1] + s[a[i]] + q[i + 1] * d[i + 1];
	}
	rep(i, 1, m * 3)
	{
		p[i] = p[i - 1] + c[a[i]];
		f[i] = f[i - 1] + s[a[i]] + p[i - 1] * d[i];
		d[i] += d[i - 1];
	}
	int w = 1;
	rep(i, m, m + m - 1)
	{
		while (d[i] - d[w] > d[w + m] - d[i]) w ++;
		int l = w - 1, r = w + m;
		s[a[i]] = f[i] - f[l] - 1ll * p[l] * (d[i] - d[l]) + g[i] - g[r] - 1ll * q[r] * (d[r] - d[i]) - s[a[i]];
	}
	rep(i, 1, m) dfs(a[i]);
	rep(i, 1, n) printf("%I64d ",s[i]);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll long long
#define ull unsignto long long
#define db double
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define ls rt << 1
#define rs rt << 1 | 1
#define sz(x) (int)(x).size()
#define ALL(x) (x).insgin(), (x).end()
#define vi vector<int>
#define cntPS 1e-8
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

const int N = 600005;
int n, m, cnt, head[N], to[N], next[N], v[N], fa[N], a[N], c[N], d[N], p[N], q[N];
ll s[N], f[N], g[N];

void ins(int u, int V, int w)
{
	to[++ cnt] = V;
	v[cnt] = w;
	next[cnt] = head[u];
	head[u] = cnt;
}

void insert(int u, int v, int w)
{
	ins(u, v, w);
	ins(v, u, w);
}
bool circle(int x)
{
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (p != fa[x])
		{
			if (fa[y])
			{
				d[++ m] = v[p];
				for (int i = x; i != y; i = to[fa[i]])
					a[m] = i, d[++ m] = v[fa[i]];
				a[m] = y;
				return 1;
			}
			else fa[y] = p ^ 1;
			if (circle(y)) return 1;
		}
	}
	return 0;
}
void dp(int x)
{
	c[x] = 1;
	s[x] = 0;
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (!fa[y])
		{
			fa[y] = x;
			dp(y);
			c[x] += c[y];
			s[x] += s[y] + c[y] * v[p];
		}
	}
}
void dfs(int x)
{
	for (int p = head[x]; p; p = next[p])
	{
		int y = to[p];
		if (fa[y] > 0 && fa[x] != y)
			s[y] = s[x] + (n - c[y] * 2) * v[p], dfs(y);
	}
}
int main()
{
	n = read();
	cnt = 1;
	rep(i, 1, n)
	{
		int x = read();
		int y = read();
		int z = read();
		insert(x, y, z);
	}
	fa[1] = -1;
	circle(1);
	rep(i, 1, n) fa[i] = 0;
	rep(i, 1, m) fa[a[i]] = -1;
	rep(i, 1, m)
	{
		a[m + m + i] = a[m + i] = a[i];
		d[m + m + i] = d[m + i] = d[i];
		dp(a[i]);
	}
	rrep(i, m * 3, 1)
	{
		q[i] = q[i + 1] + c[a[i]];
		g[i] = g[i + 1] + s[a[i]] + q[i + 1] * d[i + 1];
	}
	rep(i, 1, m * 3)
	{
		p[i] = p[i - 1] + c[a[i]];
		f[i] = f[i - 1] + s[a[i]] + p[i - 1] * d[i];
		d[i] += d[i - 1];
	}
	int w = 1;
	rep(i, m, m + m)
	{
		while (d[i] - d[w] > d[w + m] - d[i]) w ++;
		int l = w - 1, r = w + m;
		s[a[i]] = f[i] - f[l] - 1ll * p[l] * (d[i] - d[l]) + g[i] - g[r] - 1ll * q[r] * (d[r] - d[i]) - s[a[i]];
	}
	rep(i, 1, m) dfs(a[i]);
	rep(i, 1, n) printf("%I64d ",s[i]);
	return 0;
}


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

using namespace std;

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

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

bool mark[MAXN];

// bool你妹啊……
int dfs(int v, int p) {
	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;
		}
		if (w == v) {
			circ.push_back(Root(w, it->second));
			return -1;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

	dfs(0, -1);
	m = circ.size();
	for (int i = 0; i < m; ++i) {
//printf("%d--(%d)--", 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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];
//printf("calctree(%d) = %lld;\n", r.p, r.x);
}

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[q] - ee[0])) * circ[q % 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			ans[*it] += cursum + total - circ[i].x;
		}
		// 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 <stack>
#include <cstdio>
#include <vector>
#include <numeric>
#include <utility>
#include <algorithm>

using namespace std;

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

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

bool mark[MAXN];

bool dfs(int v, int p) {
	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;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

	dfs(0, -1);
	m = circ.size();
	for (int i = 0; i < m; ++i) {
//printf("%d--(%d)--", 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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[q] - ee[0])) * circ[q % m].c;
	}
//printf("cursum = %lld; curcnt = %d; q = %d\n", 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			ans[*it] += cursum + total - circ[i].x;
		}
		// 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);
//	puts("");
	for (int i = 0; i < m; ++i) {
		calctree(circ[i]);
	}
//	for (int i = 0; i < n; ++i) {
//		printf("xx[%d] = %lld\n", i, xx[i]);
//	}
	calccirc(n, m);

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

	return 0;
}


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

using namespace std;

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

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

bool mark[MAXN];

bool dfs(int v, int p) {
	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;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

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

	return m;
}

Root* root;
int cc[MAXN];
long long ss[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) {
	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;
		}
		ans[w] = ans[v] + (ss[v] - (ss[w] + cc[w] * it->second)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
//	dd[r.p] = 0;
	gao1(r.p, -1);
	ans[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	for (vector<int>::const_iterator it = r.v.begin(); it != r.v.end(); ++it) {
		ans[*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[q] - ee[0])) * circ[q % m].c;
	}
//printf("cursum = %lld; curcnt = %d; q = %d\n", 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			ans[*it] += cursum + total - circ[i].x;
		}
		// 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);
//	puts("");
	for (int i = 0; i < m; ++i) {
		calctree(circ[i]);
	}
//	for (int i = 0; i < n; ++i) {
//		printf("xx[%d] = %lld\n", i, xx[i]);
//	}
	calccirc(n, m);

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

	return 0;
}


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

using namespace std;

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

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

bool mark[MAXN];

// bool你妹啊……
int dfs(int v, int p) {
	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;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

	dfs(0, -1);
	m = circ.size();
	for (int i = 0; i < m; ++i) {
//printf("%d--(%d)--", 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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];
//printf("calctree(%d) = %lld;\n", r.p, r.x);
}

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[q] - ee[0])) * circ[q % 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			ans[*it] += cursum + total - circ[i].x;
		}
		// 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 <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 <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(v, 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--(%d)--", 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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];
//printf("calctree(%d) = %lld;\n", r.p, r.x);
}

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[q] - ee[0])) * circ[q % 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			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 <stack>
#include <cstdio>
#include <vector>
#include <numeric>
#include <utility>
#include <algorithm>

using namespace std;

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

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

bool mark[MAXN];

bool dfs(int v, int p) {
	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;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

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

	return m;
}

Root* root;
long long 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
//	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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[q] - ee[0])) * circ[q % m].c;
	}
//printf("cursum = %lld; curcnt = %d; q = %d\n", 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			ans[*it] += cursum + total - circ[i].x;
		}
		// 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);
//	puts("");
	for (int i = 0; i < m; ++i) {
		calctree(circ[i]);
	}
//	for (int i = 0; i < n; ++i) {
//		printf("xx[%d] = %lld\n", i, xx[i]);
//	}
	calccirc(n, m);

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

	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[q] - ee[0])) * circ[q % 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 = %lld; curc.x = %lld, q = %d\n", circ[i].p, cursum, circ[i].x, curcnt, 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 <stack>
#include <cstdio>
#include <vector>
#include <numeric>
#include <utility>
#include <algorithm>

using namespace std;

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

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) {
	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;
		}
		if (w == v) {
			circ.push_back(Root(w, it->second));
			return -1;
		}
		if (mark[w]) {
			circ.push_back(Root(w, it->second));
			return w;
		}
		int t = dfs(w, v);
		if (t != -1 && t != w) {
			circ.push_back(Root(w, it->second));
			return t;
		}
	}
	return -1;
}

int findcirc(int n) {
	int m;

	dfs(0, -1);
	m = circ.size();
	for (int i = 0; i < m; ++i) {
//printf("%d--(%d)--", 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) {
	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)) + (cc[v] - cc[w]) * it->second;
		gao2(w, v);
	}
}

void calctree(Root& r) {
	root = &r;
	dd[r.p] = 0;
	gao1(r.p, -1);
	xx[r.p] = 0;
	gao2(r.p, -1);
	r.c = cc[r.p];
	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];
//printf("calctree(%d) = %lld;\n", r.p, r.x);
}

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[q] - ee[0])) * circ[q % 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; q = %d\n", circ[i].p, cursum, curcnt, q);
		// update
		for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) {
			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 <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
int toward[maxn],around[maxn],sumC = 0;
int ret[maxn];
map< pair<int,int>,int > mp;
int depth[maxn],pos[maxn],treesize[maxn],intree[maxn],numChild[maxn];
int num[maxn],low[maxn],pre[maxn],cnt;
stack<int> s;

struct Tree
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + adj[u][i].second * (treesize[pos[u]] - 2 * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        int v = 0,treeSum = 0,weightSum = 0,linearSum = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) > sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) >= sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree - intree[C[u]] + intree[i] + around[u] + (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            if (!num[v])
            {
                pre[v] = u;  DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
    //freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
long long toward[maxn],around[maxn],sumC = 0,ret[maxn],depth[maxn],intree[maxn];
map< pair<int,int>,int > mp;
int pos[maxn],treesize[maxn],numChild[maxn];
int num[maxn],low[maxn],pre[maxn],cnt;
stack<int> s;

struct Tree
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + 1LL * adj[u][i].second * (treesize[pos[u]] - 2LL * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        long long treeSum = 0,weightSum = 0,linearSum = 0;
        int v = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= 1LL * treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (2LL * (linearSum + mp[make_pair(C[v],C[k])]) > sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += 1LL * linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= 1LL * treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (2LL * (linearSum + mp[make_pair(C[v],C[k])]) >= sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += 1LL * linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree - intree[C[u]] + intree[i] + around[u] + 1LL * (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%I64d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            if (!num[v])
            {
                pre[v] = u;  DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
    //freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
int toward[maxn],around[maxn],sumC = 0;
int ret[maxn];
map< pair<int,int>,int > mp;
int depth[maxn],pos[maxn],treesize[maxn],intree[maxn],numChild[maxn];
int num[maxn],low[maxn],pre[maxn],cnt;
stack<int> s;

struct Tree
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + adj[u][i].second * (treesize[pos[u]] - 2 * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        int v = 0,treeSum = 0,weightSum = 0,linearSum = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) > sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) >= sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree - intree[C[u]] + intree[i] + around[u] + (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            pre[v] = u;
            if (!num[v])
            {
                DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
  //  freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
int toward[maxn],around[maxn],sumC = 0;
int ret[maxn];
map< pair<int,int>,int > mp;
int depth[maxn],pos[maxn],treesize[maxn],intree[maxn],numChild[maxn];
int num[maxn],low[maxn],pre[maxn],cnt;
stack<int> s;

struct Tree
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }

        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + adj[u][i].second * (n - 2 * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        int v = 0,treeSum = 0,weightSum = 0,linearSum = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) > sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) >= sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree + around[u] + (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            pre[v] = u;
            if (!num[v])
            {
                DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
    //freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
int toward[maxn],around[maxn],sumC = 0;
int ret[maxn];
map< pair<int,int>,int > mp;

struct Tree
{
    vector< pair<int,int> > adj[maxn];
    int depth[maxn],pos[maxn],treesize[maxn],intree[maxn],numChild[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }

        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin(),adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + adj[u][i].second * (n - 2 * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        int v = 0,treeSum = 0,weightSum = 0,linearSum = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (linearSum + mp[make_pair(C[v],C[k])] > sumC/2) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (linearSum + mp[make_pair(C[v],C[k])] >= sumC/2) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree + around[u] + (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];
    int num[maxn],low[maxn],pre[maxn],cnt;
    stack<int> s;

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            pre[v] = u;
            if (!num[v])
            {
                DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
//    freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define maxn 200006
using namespace std;

int n;
vector<int> C;
int toward[maxn],around[maxn],sumC = 0;
int ret[maxn];
map< pair<int,int>,int > mp;

struct Tree
{
    vector< pair<int,int> > adj[maxn];
    int depth[maxn],pos[maxn],treesize[maxn],intree[maxn],numChild[maxn];

    void load()
    {
        memset(pos,-1,sizeof(pos));
        memset(depth,0,sizeof(depth));
        memset(treesize,0,sizeof(treesize));
        memset(intree,0,sizeof(intree));
        memset(numChild,0,sizeof(numChild));

        for (int i = 0; i < C.size(); i++)
        {
            pos[C[i]] = i;  DFS(C[i],-1,i);
        }

        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];  intree[C[u]] += depth[i];
        }

        for (int i = 0; i < C.size(); i++) DFScalc(C[i]);
    }

    void DFS(int u,int pre,int comIdx)
    {
        treesize[comIdx]++;  numChild[u] = 1;
        int preIdx = -1;
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (v == pre) preIdx = i; else
            {
                depth[v] = depth[u] + adj[u][i].second;  pos[v] = comIdx;
                DFS(v,u,comIdx);
                numChild[u] += numChild[v];
            }
        }
        if (preIdx >= 0) adj[u].erase(adj[u].begin(),adj[u].begin() + preIdx);
    }

    void DFScalc(int u)
    {
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            intree[v] = intree[u] + adj[u][i].second * (n - 2 * numChild[v]);
            DFScalc(v);
        }
    }

    void goAround()
    {
        memset(around,0,sizeof(around));
        int v = 0,treeSum = 0,weightSum = 0,linearSum = 0;
        for (int u = 0; u < C.size(); u++)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u - 1],C[u])];
                linearSum -= mp[make_pair(C[u - 1],C[u])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = (v + 1) % C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) > sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] = weightSum;
        }
        v = C.size() - 1; weightSum = linearSum = treeSum = 0;
        for (int u = C.size() - 1; u >= 0; u--)
        {
            if (linearSum)
            {
                weightSum -= treeSum * mp[make_pair(C[u],C[u + 1])];
                linearSum -= mp[make_pair(C[u],C[u + 1])];
                treeSum -= treesize[u];
            }
            else
            {
                v = u;  weightSum = linearSum = treeSum = 0;
            }

            while (1)
            {
                int k = v - 1;  if (k < 0) k += C.size();
                if (2 * (linearSum + mp[make_pair(C[v],C[k])]) >= sumC) break; else
                {
                    linearSum += mp[make_pair(C[v],C[k])];
                    weightSum += linearSum * treesize[k];
                    treeSum += treesize[k];
                    v = k;
                }
            }
            around[u] += weightSum;
        }
    }

    void answer()
    {
        int sumTree = 0;
        for (int i = 0; i < C.size(); i++) sumTree += intree[C[i]];

        memset(ret,0,sizeof(ret));
        for (int i = 1; i <= n; i++)
        {
            int u = pos[i];
            ret[i] = sumTree + around[u] + (n - treesize[u]) * depth[i];
        }
        for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
        printf("\n");
    }
} T;

struct Graph
{
    vector< pair<int,int> > adj[maxn];
    int num[maxn],low[maxn],pre[maxn],cnt;
    stack<int> s;

    void load()
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            int u,v,c;  scanf("%d %d %d", &u, &v, &c);
            adj[u].push_back(make_pair(v,c));
            adj[v].push_back(make_pair(u,c));
        }
        memset(num,0,sizeof(num));
        memset(low,0,sizeof(low));
        memset(pre,-1,sizeof(pre));
    }

    void DFS(int u)
    {
        num[u] = low[u] = ++cnt;  s.push(u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i].first;
            if (pre[u] == v) continue;
            pre[v] = u;
            if (!num[v])
            {
                DFS(v);  low[u] = min(low[u],low[v]);
            }
            else low[u] = min(low[u],low[v]);
        }

        if (low[u] == num[u])
        {
            vector<int> p;
            while (1)
            {
                int x = s.top();  s.pop();  p.push_back(x);  if (x == u) break;
            }
            if (p.size() < 3) return;
            C = p;
            for (int i = 0; i < C.size(); i++)
            {
                int u = C[i],v = C[(i + 1) % C.size()];
                mp[make_pair(u,v)] = mp[make_pair(v,u)] = true;
            }
        }
    }

    void final()
    {
        for (int u = 1; u <= n; u++)
          for (int i = 0; i < adj[u].size(); i++)
          {
              int v = adj[u][i].first;
              if (!mp.count(make_pair(u,v))) T.adj[u].push_back(adj[u][i]); else mp[make_pair(u,v)] = adj[u][i].second;
          }
        toward[C[0]] = 0;
        for (int i = 1; i < C.size(); i++)
          toward[C[i]] = toward[C[i - 1]] + mp[make_pair(C[i - 1],C[i])];
        sumC = toward[C[C.size() - 1]] + mp[make_pair(C[0],C[C.size() - 1])];
    }
} G;

int main()
{
//    freopen("g.in","r",stdin);

    scanf("%d", &n);
    G.load();
    G.DFS(1);
    G.final();
    T.load();
    T.goAround();
    T.answer();
}


#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

typedef struct {
    vector <int> next;
    vector <int> t;
    bool onCycle;
    int size;
} planet;

typedef struct {
    vector <int> child;
    vector <int> t;
    vector <int> size;
    vector <long long> weight;
    long long total_weight;
    int total_size;
    int dp;
} cycle_planet;

int n, m;

planet p[300000];
bool found[300000];
int prev[300000];
int prev2[300000];
long long ans[300000];
bool use[300000];
int cycle_total = 0;
long long tree_total = 0;
map <pair <int, int>, int>  weight;

bool made_cycle = false;
vector <int> cycle;
cycle_planet cp[300000];

int dist[300000]; /* least distance from i to a point on the cycle */

int cycle_dist (int i, int j)
{
    if (i == j) return 0;
    if (j < i) return cycle_dist (j, i);
    return min(cp[j].dp - cp[i].dp, cycle_total - (cp[j].dp - cp[i].dp));
}

int right_dist (int i, int j)
{
    if (i == j) return 0;
    int d = cp[j].dp - cp[i].dp + cycle_total;
    return d % cycle_total;
}

int left_dist (int i, int j)
{
    if (i == j) return 0;
    int d = cp[i].dp - cp[j].dp + cycle_total;
    return d % cycle_total;
}

void compute(int v, int parent)
{
    ans[v] = ans[parent] + weight[make_pair(v, parent)] * (n - 2 * (p[v].size));
    // printf("ans %d: %d\n", v, ans[v]);
    for (int i = 0; i < p[v].next.size(); i++)
    {
        int w = p[v].next[i];
        if (w == parent) continue;
        compute(w, v);
    }
}

void get_cycle(int v, int before)
{
    if (made_cycle) return;
    if (!found[v])
    {
        found[v] = true;
        for (int i = 0; i < p[v].next.size(); i++)
        {
            int w = p[v].next[i];
            if (w == before) continue;
            prev[w] = v;
            get_cycle(w, v);
        }
    }
    else
    {
        p[v].onCycle = true;
        cycle.push_back(v);

        int a = prev[v];
        while (a != v)
        {
            cycle.push_back(a);
            p[a].onCycle = true;
            a = prev[a];
        }
        made_cycle = true;
    }
}

int tree_size(int v, int parent)
{
    int sum = 1;
    for (int i = 0; i < p[v].next.size(); i++)
    {
        int w = p[v].next[i];
        if (w == parent) continue;
        sum += tree_size(w, v);
    }
    p[v].size = sum;
    return sum;
}

long long tree_weight(int v, int parent)
{
    long long sum = dist[v];
    for (int i = 0; i < p[v].next.size(); i++)
    {
        int w = p[v].next[i];
        if (w == parent) continue;
        sum += tree_weight(w, v);
    }
    return sum;
}

void Dijkstra (int v)
{
    dist[v] = 0;
    priority_queue < pair <int, int> > pq;
    pq.push(make_pair(-0, v));
    while (!pq.empty())
    {
        pair <int, int> next = pq.top();
        int w = next.second;
        pq.pop();

        if (use[w]) continue;
        use[w] = true;
        for (int i = 0; i < p[w].next.size(); i++)
        {
            int u = p[w].next[i];
            if (p[u].onCycle || use[u]) continue;
            dist[u] = min(dist[u], dist[w] + p[w].t[i]);
            pq.push(make_pair(-dist[u], u));
        }
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int a, b, t;
        scanf("%d %d %d", &a, &b, &t);
        p[a].next.push_back(b);
        p[b].next.push_back(a);
        p[a].t.push_back(t);
        p[b].t.push_back(t);
        weight[make_pair(a, b)] = t;
        weight[make_pair(b, a)] = t;
        // printf("%d %d %d\n", a, b, weight[make_pair(b, a)]);

        found[i] = false;
        p[i].onCycle = false;
        prev[i] = -1;
        prev2[i] = -1;
        dist[i] = (int) 1e9;
        use[i] = false;
        ans[i] = 0;
    }
    get_cycle(1, -1);
    m = cycle.size();
    // printf("cycle:\n");
    int curdp = 0;
    for (int i = 0; i < cycle.size(); i++)
    {
        // printf(" %d\n", cycle[i]);
        Dijkstra(cycle[i]);
        if (i != 0)
        {
            curdp += weight[make_pair(cycle[i], cycle[i - 1])];
            // printf("%d %d %d\n", cycle[i], cycle[i - 1], weight[make_pair(cycle[i], cycle[i - 1])]);
        }
        cp[i].total_size = 1;
        cp[i].total_weight = 0;
        cp[i].dp = curdp;
        for (int j = 0; j < p[cycle[i]].next.size(); j++)
        {
            if (p[p[cycle[i]].next[j]].onCycle)
            {
                continue;
            }
            cp[i].child.push_back(p[cycle[i]].next[j]);
            cp[i].t.push_back(p[cycle[i]].t[j]);
            cp[i].size.push_back(tree_size(p[cycle[i]].next[j], cycle[i]));
            cp[i].weight.push_back(tree_weight(p[cycle[i]].next[j], cycle[i]));
            cp[i].total_size += cp[i].size[cp[i].size.size() - 1];
            cp[i].total_weight += cp[i].weight[cp[i].weight.size() - 1];
        }
        // printf("size: %d\n", cp[i].total_size);
        // printf("total_weight: %I64d\n", cp[i].total_weight);
        // printf("dp: %d\n", cp[i].dp);
        tree_total += cp[i].total_weight;
    }
    cycle_total = curdp + weight[make_pair(cycle[0], *(cycle.end() - 1))];
    // printf("\n");
    // printf("distance\n");
    /* for (int i = 1; i <= n; i++)
    {
        printf("%d %d\n", i, dist[i]);
    } */
    // printf("cycle total: %d\n", cycle_total);
    // printf("tree total: %I64d\n", tree_total);
    /* for (int i = 0; i < cycle.size(); i++)
    {
        for (int j = 0; j < cycle.size(); j++)
        {
            printf("dist %d %d: %d\n", cycle[i], cycle[j], cycle_dist(i, j));
        }
    } */
    int left = 0;
    int right = 0;
    int index = 0;
    ans[cycle[0]] = tree_total;
    for (int i = 0; i < cycle.size(); i++)
    {
        if (i == 0)
        {
            left += cp[i].total_size;
        }
        else if (right_dist(0, i) < left_dist(0, i))
        {
            right += cp[i].total_size;
            index = i;
        }
        else
        {
            left += cp[i].total_size;
        }
        ans[cycle[0]] += cp[i].total_size * cycle_dist(0, i);
    }
    // printf("ans %d: %I64d\n", cycle[0], ans[cycle[0]]);
    // printf("%d %d %d\n", left, right, index);
    for (int i = 1; i < m; i++)
    {
        if (index == i - 1)
        {
            int swap = right;
            right = left;
            left = swap;
            ans[cycle[i]] = tree_total;
            for (int j = 0; j < m; j++)
            {
                ans[cycle[i]] += cp[j].total_size * cycle_dist(i, j);
            }
        }
        else
        {
            int t = weight[make_pair(cycle[i - 1], cycle[i])];
            ans[cycle[i]] = ans[cycle[i - 1]] + (left - right) * t;
            while (right_dist(i, (index + 1) % m) < left_dist(i, (index + 1) % m))
            {
                index = (index + 1) % m;
                right += cp[index].total_size;
                left  -= cp[index].total_size;
                ans[cycle[i]] -= (left_dist(i, index) - right_dist(i, index)) * cp[index].total_size;
            }
        }
        right -= cp[i].total_size;
        left += cp[i].total_size;
        // printf("ans %d: %I64d\n", cycle[i], ans[cycle[i]]);
        // printf("%d %d %d\n", left, right, index);
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < cp[i].child.size(); i++)
        {
            compute(cp[i].child[j], cycle[i]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        printf("%d ", ans[i]);
    }
    fflush(stdin);
    getchar();
}