#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x0123456789) cerr<<#x0123456789<<':'<<x0123456789<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x0123456789:v)cerr<<x0123456789<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

struct Graph{
  long long V;
  long long E;
  //u,v,weight,cap
  vector<tuple<long long,long long,long long,long long>> edges;
  void add(long long u,long long v,long long weight){edges.push_back(make_tuple(u,v,weight,0));}
  void add(long long u,long long v,long long weight,long long capacity){edges.push_back(make_tuple(u,v,weight,capacity));}
};

//ワーシャルフロイド法(負閉路検出時はv[0].size()が0のvectorを返す)
vector<vector<long long>> WarshallFloyd(const Graph &G){long long adj[G.V][G.V];for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)adj[i][j] = (i==j ? 0 : 1000000000000000007);for(long long i=0;i<G.E;i++)adj[get<0>(G.edges[i])][get<1>(G.edges[i])] = get<2>(G.edges[i]);for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)for(long long k=0;k<G.V;k++)if(adj[j][i] != 1000000000000000007 && adj[i][k] != 1000000000000000007)adj[j][k] = min(adj[j][k],adj[j][i]+adj[i][k]);vector<vector<long long>> ans(G.V);for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)for(long long k=0;k<G.V;k++)if(adj[j][i] != 1000000000000000007 && adj[i][k] != 1000000000000000007 && adj[j][k] > adj[j][i]+adj[i][k])return ans;for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)ans[i].push_back(adj[i][j]);return ans;}

//ダイクストラ法(到達不可能なら-1を返す)
vector<long long> Dijkstra(const Graph &G,const long long &start){vector<vector<pair<long long,long long>>> adj(G.V);for(auto t:G.edges)adj[get<0>(t)].push_back(make_pair(get<1>(t),get<2>(t)));vector<long long> dmin(G.V,-1);priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pque;pque.push(make_pair(0,start));pair<long long,long long> p;while(pque.size()){p = pque.top();pque.pop();if(dmin[p.second] == -1){dmin[p.second] = p.first;for(auto x:adj[p.second]){if(dmin[x.first] == -1)pque.push(make_pair(dmin[p.second]+x.second,x.first));}}}return dmin;}

//ベルマンフォード法(負閉路を含む場合はsize0,到達不可能ならLINFを返す)))
vector<long long> BellmanFord(const Graph &G,const long long &start){vector<long long> dmin(G.V,1000000000000000007);dmin[start] = 0;for(long long i=0;i<G.V-1;i++)for(long long j=0;j<G.E;j++)if(dmin[get<0>(G.edges[j])] != 1000000000000000007)dmin[get<1>(G.edges[j])] = min(dmin[get<1>(G.edges[j])],dmin[get<0>(G.edges[j])]+get<2>(G.edges[j]));vector<long long> ans;for(long long j=0;j<G.E;j++)if(dmin[get<0>(G.edges[j])] != 1000000000000000007)if(dmin[get<1>(G.edges[j])] > dmin[get<0>(G.edges[j])]+get<2>(G.edges[j]))return ans;return dmin;}

//最大フロー
long long max_flow(const Graph &G,const long long &start,const long long &end){long long cf[G.V][G.V],ans=0;for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)cf[i][j]=0;for(long long i=0;i<G.E;i++)cf[get<0>(G.edges[i])][get<1>(G.edges[i])]=get<3>(G.edges[i]);queue<long long> que;while(1){que.push(start);long long dmin[G.V];for(long long i=0;i<G.V;i++)dmin[i]=-1;dmin[start]=0;while(que.size()){long long n=que.front();for(long long i=0;i<G.V;i++){if(n!=i&&cf[n][i]>0&&dmin[i]==-1){dmin[i]=n;que.push(i);}}que.pop();}if(dmin[end]==-1)break;vector<long long> way;long long n=end;while(n!=start){way.push_back(n);n=dmin[n];}way.push_back(start);long long MIN=1000000007;for(long long i=0;i<way.size()-1;i++)MIN=min(MIN,cf[way[i+1]][way[i]]);for(long long i=0;i<way.size()-1;i++){cf[way[i]][way[i+1]]+=MIN;cf[way[i+1]][way[i]]-=MIN;}ans += MIN;}return ans;}

long long Diameter(const Graph &G){vector<long long> d=Dijkstra(G,0);long long m=0,M;for(long long i=0;i<G.V;i++)if(m<=d[i])m=d[i],M=i;d=Dijkstra(G,M);m=0;for(long long i=0;i<G.V;i++)m=max(m,d[i]);return m;}

signed main(){
    ll n,s,t,w;
    cin >> n;
    Graph G;
    G.V = n;
    G.E = n-1;
    FOR(i,0,n-1){
        cin >> s >> t >> w;
        G.add(s,t,w);
        G.add(t,s,w);
    }
    cout << Diameter(G) << endl;
}


Measured memory_bytes: 18808