#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;
vector <bool> vis(100005);
void dfs(int i,int p,int cur){
vis[i]=true;
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);
}
int res = 0;
for(int i = 1;i <= n;i++){
if(!vis[i]){
point = i;
dfs(i,-1,1);
dfs(point,-1,1);
res += maxi;
maxi = 1;
}
}
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3160 KB |
Output is correct |
2 |
Correct |
9 ms |
3676 KB |
Output is correct |
3 |
Correct |
16 ms |
4188 KB |
Output is correct |
4 |
Correct |
16 ms |
4956 KB |
Output is correct |
5 |
Correct |
20 ms |
5388 KB |
Output is correct |
6 |
Correct |
23 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
10440 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
4 ms |
3676 KB |
Output is correct |
4 |
Correct |
6 ms |
4276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
6 |
Correct |
5 ms |
3932 KB |
Output is correct |
7 |
Correct |
7 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2904 KB |
Output is correct |
10 |
Correct |
1 ms |
2828 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3160 KB |
Output is correct |
2 |
Correct |
9 ms |
3676 KB |
Output is correct |
3 |
Correct |
16 ms |
4188 KB |
Output is correct |
4 |
Correct |
16 ms |
4956 KB |
Output is correct |
5 |
Correct |
20 ms |
5388 KB |
Output is correct |
6 |
Correct |
23 ms |
5980 KB |
Output is correct |
7 |
Correct |
21 ms |
10440 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
4 ms |
3676 KB |
Output is correct |
10 |
Correct |
6 ms |
4276 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
3 ms |
3164 KB |
Output is correct |
16 |
Correct |
5 ms |
3932 KB |
Output is correct |
17 |
Correct |
7 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2904 KB |
Output is correct |
27 |
Correct |
1 ms |
2828 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
30 ms |
6964 KB |
Output is correct |
30 |
Correct |
8 ms |
3828 KB |
Output is correct |
31 |
Correct |
16 ms |
6492 KB |
Output is correct |
32 |
Correct |
10 ms |
4696 KB |
Output is correct |
33 |
Correct |
21 ms |
7004 KB |
Output is correct |
34 |
Correct |
14 ms |
5212 KB |
Output is correct |
35 |
Correct |
24 ms |
6988 KB |
Output is correct |
36 |
Correct |
18 ms |
5700 KB |
Output is correct |
37 |
Correct |
22 ms |
6748 KB |
Output is correct |
38 |
Correct |
22 ms |
6456 KB |
Output is correct |
39 |
Correct |
20 ms |
6632 KB |
Output is correct |