#include <iostream>
#include <vector>
using namespace std;

struct edge{
	int to, cost;

	edge(int to, int cost){
		this->to = to;
		this->cost = cost;
	}
};

pair<int, int> diameter(vector<vector<edge>> &v, int now = 0, int dist = 0, int par = -1){
	pair<int, int> r(dist, now);
	for(auto &next:v[now]) if(next.to != par){
		pair<int, int> d = diameter(v, next.to, dist + next.cost, now);
		if(r.first < d.first) r = d;
	}
	return r;
}

int main(){
	int n;
	cin >> n;
	vector<vector<edge>> v(n);
	for(int i = 0; i < n - 1; i++){
		int from, to, cost;
		cin >> from >> to >> cost;
		v[from].emplace_back(edge(to, cost));
		v[to].emplace_back(edge(from, cost));
	}
	cout << diameter(v, diameter(v).second).first << endl;
}