#include
#include
#include
#include
#include
#include
#include
#define rl(x) scanf("%lld",&x)
#define ll long long
using namespace std;
ll cou=0,x,c,w;
#define pii pair<int,int>
vectorG[50005];
int main()
{
ll t;
rl(t);
while(t–)
{
ll n,u,v,x,dis,res,m=0,ed;
rl(n);
ll vis[n+5];
for(ll i=0;i<n-1;i++)
{
rl(u),rl(v),rl(w);
G[u].push_back(pii(v,w));
G[v].push_back(pii(u,w));
}
memset(vis,0,sizeof(vis));
queueQ;
Q.push(pii(1,0));
vis[1]=1;
while(!Q.empty())
{
x=Q.front().first;
for(ll i=0;i<G[x].size();i++)
{
ed=G[x][i].first;
c=G[x][i].second;
if(!vis[ed])
{
vis[ed]=1;
dis=Q.front().second+c;
if(m<=dis)
{
m=dis;
res=ed;
}
Q.push(pii(ed,dis));
}
}
Q.pop();
}
//printf(“res=%lld len=%lld”,res,m);
memset(vis,0,sizeof(vis));
Q.push(pii(res,0));
vis[res]=1;
while(!Q.empty())
{
x=Q.front().first;
for(ll i=0;i<G[x].size();i++)
{
ed=G[x][i].first;
c=G[x][i].second;
if(!vis[ed])
{
vis[ed]=1;
dis=Q.front().second+c;
if(m<=dis)
{
m=dis;
res=ed;
}
//cout<<“pushing “<<ed<<” “<<dis<<endl;
Q.push(pii(ed,dis));
}
}
Q.pop();
}
printf(”%lld\n”,dis);
for(ll i=1;i<=n;i++)
G[i].clear();
}
}
what is wrong in the code i am getting wrong answer can any one please help me thanks in advance