#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 10002
vector<pair<int, int>> node[MAX];
bool vis[MAX];
int res, endPoint;
void DFS(int p = 1, int len = 0)
{
if (vis[p])
return;
vis[p] = true;
if (res < len)
{
res = len;
endPoint = p;
}
for (int i = 0; i < node[p].size(); i++)
DFS(node[p][i].first, len + node[p][i].second);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
for (int i = 0; i < n - 1; i++)
{
int a, b, c; cin >> a >> b >> c;
node[a].push_back({ b, c });
node[b].push_back({ a, c });
}
DFS();
res = 0;
fill(vis, vis + MAX, false);
DFS(endPoint);
cout << res;
return 0;
}