Pagini recente » Cod sursa (job #2938678) | Cod sursa (job #2465693) | Cod sursa (job #1884794) | Cod sursa (job #2047484) | Cod sursa (job #3214919)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
using pii = pair<int,int>;
ifstream cin("darb.in");
ofstream cout("darb.out");
const int nmax = 1e5 + 1;
int n , x , y , dp[nmax];
bool viz[nmax];
vector <int> g[nmax];
signed main()
{
cin >> n;
for(int i = 1 ; i < n ; ++i)
{
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
queue<int>q;
viz[1] = 1;
q.push(1);
int last = -1;
while(!q.empty())
{
x = q.front();
q.pop();
last = x;
for(auto it : g[x])
{
if(!viz[it])
{
viz[it] = 1;
q.push(it);
}
}
}
dp[last] = 1;
q.push(last);
while(!q.empty())
{
x = q.front(); q.pop();
last = x;
for(auto it : g[x])
{
if(!dp[it])
{
dp[it] = dp[x] + 1;
q.push(it);
}
}
}
cout << dp[last];
return 0;
}