#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";}
vector <int> adj[100005];
int point = 1;
int maxi = 1;
void dfs(int i,int p,int cur){
if(cur > maxi){
maxi = cur;
point = i;
}
for(int j : adj[i]){
if(j != p){
dfs(j,i,cur+1);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,m;
cin >> n >> m;
for(int i = 0;i < m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,-1,1);
dfs(point,-1,1);
cout << maxi << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3416 KB |
Output is correct |
2 |
Correct |
10 ms |
4064 KB |
Output is correct |
3 |
Correct |
13 ms |
4952 KB |
Output is correct |
4 |
Correct |
16 ms |
5720 KB |
Output is correct |
5 |
Correct |
20 ms |
6236 KB |
Output is correct |
6 |
Correct |
25 ms |
7200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
9556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3416 KB |
Output is correct |
2 |
Correct |
10 ms |
4064 KB |
Output is correct |
3 |
Correct |
13 ms |
4952 KB |
Output is correct |
4 |
Correct |
16 ms |
5720 KB |
Output is correct |
5 |
Correct |
20 ms |
6236 KB |
Output is correct |
6 |
Correct |
25 ms |
7200 KB |
Output is correct |
7 |
Incorrect |
22 ms |
9556 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |