#include "iostream"
#include "cstring"
#include "cstdio"
#include "set"
#include "map"
#include "algorithm"
#include "vector"
#include "queue"
#include "cassert"
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> PII;
const int N = 100010;

vector<PII> e[N];
vector<int> node;
int balence[N], visit[N], size[N];
void dfs(int x, int fa)
{
	size[x] = 1;
	balence[x] = 0;
	for(int i = 0; i < e[x].size(); ++ i){
		int u = e[x][i].F;
		if(u == fa || visit[u]) continue;
		dfs(u);
		size[x] += size[u];
		balence[x] = max(balence[x], size[u]);
	}
	node.PB(x);
}

int GetRoot(int x)
{
	dfs(x, -1);
	node.clear();
	int total = size[x];
	int root = node[0];
	int val = max(balence[root], total - size[root]);
	for(int i = 1; i < node.size(); ++ i){
		int u = node[i];
		int tmp = max(balence[u], total - size[u]);
		if(tmp < val){
			val = tmp;
			root = u;
		}
	}
	return root;
}
long long ans = 0;
map<int, int> mp;
void dfs2(int x, int pa, int depth)
{
	mp[depth] ++;
	
void solve(int x)
{
	visit[x] = 1;
	int root = GetRoot(x);
	dfs2(root, -1, 0);
	for(int i = 0; i < e[x].size(); ++ i){
		int u = e[x][i];
		if(!visit[u]){
			solve(u);
		}
	}
}
int main(void)
{
	int n, x, y, w;
	scanf("%d",&n);
	for(int i = 1; i < n; ++ i){
		cin >> x >> y >> w;
		e[x].PB(MP(y, w));
		e[y].PB(MP(x, w));
	}
	ans = 0;
	solve(1);
	cout << ans << endl;
	return 0;
}