Pagini recente » Cod sursa (job #1611722) | Cod sursa (job #442123) | Cod sursa (job #1611713) | Istoria paginii runda/sim_oni_2010_ziua1/clasament | Cod sursa (job #2342664)
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
ifstream fin("darb.in");
ofstream fout("darb.out");
const int NMax = 1e5;
vector <int> G[NMax + 5];
int N, NodM, Max, D[NMax + 5];
void Read()
{
fin >> N;
for(int i = 1, x, y; i < N; i++)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFS(int Nod, int Tata)
{
D[Nod] = D[Tata] + 1;
if(D[Nod] > Max) Max = D[Nod], NodM = Nod;
for(auto Vecin : G[Nod])
if(Vecin != Tata)
DFS(Vecin, Nod);
}
void Solve()
{
DFS(1, 0);
memset(D, 0, sizeof(D));
DFS(NodM, 0);
fout << Max << '\n';
}
int main()
{
Read();
Solve();
fin.close();
fout.close();
return 0;
}