用树形dp来求
贴个板子自己用~
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e5+10;
const ll mod=1e9+7;
struct ty{
ll l,t,next;
}edge[N<<1];
ll cnt=0;
ll head[N];
ll f1[N],f2[N];
ll n,a,b,c;
void add(ll a,ll b,ll c)
{
edge[++cnt].l=c;
edge[cnt].t=b;
edge[cnt].next=head[a];
head[a]=cnt;
}
ll leng=0;
void dfs(ll u,ll fa)
{
for(int i=head[u];i!=-1;i=edge[i].next)
{
ll y=edge[i].t;
if(y==fa) continue;
dfs(y,u);
if(f1[u]<f1[y]+edge[i].l)
{
f2[u]=f1[u];
f1[u]=f1[y]+edge[i].l;
}
else if(f2[u]<f1[y]+edge[i].l)
{
f2[u]=f1[y]+edge[i].l;
}
leng=max(leng,f1[u]+f2[u]);
}
}
int main()
{
memset(head,-1,sizeof head);
cin>>n;
for(int i=1;i<n;++i)
{
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
dfs(1,-1);
ll length=leng;
cout<<(length*10)+((length+1)*length/2)<<endl;
return 0;
}