one more doubt let say we have undirected +ve weighted tree , Now we have to Find two vertices the distance between which is minimum , not need to print vertices just print distance , so what we can do is -

```
lli dp[n][n];
loop(i,n)
{
loop(j,n)
{
if(i==j)
dp[i][j]=0;
else
dp[i][j] = INF;
}
}
loop(i,m)
{
lli x,y,cost;
cin>>x>>y>>cost;
--x;
y--;
dp[x][y] = cost;
dp[y][x] = cost;
}
loop(k,n)
{
loop(i,n)
{
loop(j,n)
{
dp[i][j] = min(dp[i][j] , dp[i][k]+dp[k][j]);
}
}
}
lli ans = INF;
loop(i,n)
loop(j,n)
if(i!=j)
ans = min(ans , dp[i][j])
print(ans);
```

But what if we have to find the maximum distance , I did by taking -INF but not correct answer.

@ssjgz @spaanse