#include  <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

const int vmax=100010;

int N,M;
struct node{ int to,cost;};
vector<node> graph[vmax];

int dist[vmax];

int diameter(int n){
	function<void(int,int,int)> dfs=[&dfs](int v,int p,int c){
		dist[v]=c;
		for(auto &e:graph[v]) if(e.to!=p) dfs(e.to,v,c+e.cost);
	};
	dfs(0,-1,0);
	int root=max_element(dist,dist+n)-dist;
	dfs(root,-1,0);
	return *max_element(dist,dist+n);
}

int main(void){
	cin >> N;
	rep(i,N-1){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].push_back({b,c});
		graph[b].push_back({a,c});
	}
	cout << diameter(N) << endl;
	return 0;
}