#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#define M 100000
using namespace std;

struct edge {
	int t, w;
};

int D = 0, x;
vector<edge> G[M];

void Serch(int u, int v, int d) {
	for (int i = 0; i < G[u].size(); i++) {
		if (G[u][i].t != v) {
			Serch(G[u][i].t, u, d + G[u][i].w);
		}
	}
	if (D < d) { D = d; x = u; }
}

int main() {
	int n, s, t, w, dia = 0;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> s >> t >> w;
		edge a, b; a.t = t; b.t = s; a.w = b.w = w;
		G[s].push_back(a); G[t].push_back(b);
	}

	Serch(0, -1, 0);
	D = 0;
	Serch(x, -1, 0);

	cout << D << endl;
	return 0;
}
