//给定一个含有n个节点的树,以及每条条的权值,求俩点的最大距离
//状态表示f1[i],最大距离,f2[i],次大距离
//状态转移:if :f1[i]>f1[j]+edge[j],f2[i]=f1[i],f1[i]=f1[j]+edge[j]
// else if:f2[i]>f1[j]+edge[j],f2[i]=f1[j]+edge[j]
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e4 + 10, M = N << 1;
int f1[N],f2[N];
int idx,w[M],ne[M],e[M],h[M];
int res=0;
void add(int a,int b,int c)
{
e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u,int father)
{
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
if(j==father)continue;
dfs(j,u);
if(f1[j]+w[i]>=f1[u])f2[u]=f1[u],f1[u]=f1[j]+w[i];
else if(f1[j]+w[i]>f2[u])f2[u]=f1[j]+w[i];
}
res=max(res,f1[u]+f2[u]);
}
int main()
{
memset(h,-1,sizeof h);
int n;
cin>>n;
for(int i=0;i<n-1;i++)
{
int a,b,c;
cin>>a>>b>>c;
add(a,b,c),add(b,a,c);
}
dfs(1,-1);
cout<<res;
return 0;
}