-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPT07Z.cpp
More file actions
43 lines (41 loc) · 675 Bytes
/
Copy pathPT07Z.cpp
File metadata and controls
43 lines (41 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<vector>
#include<stack>
#include<limits>
#include<algorithm>
using namespace std;
int main()
{
int N;
cin>>N;
vector<vector<int> > adj(N+1, vector<int>(N+1));
stack<int> S;
for (int i = 1; i < N; ++i)
{
int a = 0, b = 0;
cin>>a>>b;
adj[a][b] = 1;
adj[b][a] = 1;
}
int len = numeric_limits<int>::min();
for(int i = 1; i <= N; i++)
{
S.push(i);
vector<int> dist(N+1,0);
while(!S.empty())
{
dist[i] = 0;
for (int j = 1; j <= N; ++j)
{
if(adj[S.top()][j] == 1 and visited[j] == 0)
{
visited[j] = 1;
arr[j] = arr[S.top()] + 1;
S.push(j);
}
}
}
}
cout<<len<<"\n";
return 0;
}