https://vjudge.net/contest/279738#problem/G
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct str
{
int t,w,n;
}e[1000000];
int a,b,c,t,i,j,k,l,n,ans,m,max1,h[200010],v[100010],d[200010];
void add(int u,int v,int w)
{
t++;
e[t].t=v;
e[t].w=w;
e[t].n=h[u];
h[u]=t;
}
void bfs(int x)
{
queue<int>q;
q.push(x);
max1=0;
memset(v,0,sizeof(v));
memset(d,0x3f3f3f3f,sizeof(d));
d[x]=0;
ans=0;
while (q.size())
{
int t1=q.front();
q.pop();
if (v[t1]==1) continue;
v[t1]=1;
for (int i=h[t1]; i; i=e[i].n)
{
int t2=e[i].t;
if (d[t2]>d[t1]+e[i].w)
{
d[t2]=d[t1]+e[i].w;
q.push(t2);
if (d[t2]>max1)
{
max1=d[t2];
ans=t2;
}
}
}
}
}
int main()
{
while (~scanf("%d%d%d",&a,&b,&c))
{
add(a,b,c);
add(b,a,c);
}
bfs(1);
bfs(ans);
printf("%d\n",max1);
}