#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define endl "\n"
vector< vector<pair<int, int>> > g(100006);
int node = 0;
int ans = -1;

void getnode(int u, int par, int dis) {
	int flg = 0;
	for (int i=0; i<g[u].size(); i++) {
		if (g[u][i].first != par) {
			getnode(g[u][i].first, u, g[u][i].second+dis);
			flg = 1;
		}
	}
	if (flg == 0) {
		if (dis > ans) {
			ans = dis;
			node = u;
		}
	}
}


void testCase() {
	int n;
	cin >> n;
	for (int i=1; i<n; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		g[u].push_back(make_pair(v, w));
		g[v].push_back(make_pair(u, w));
	}
	getnode(0, -1, 0);
	//cout << node << endl;
	ans = -1;
	getnode(node, -1, 0);
	cout << ans << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	return 0;
}
