#include <bits/stdc++.h>
using namespace std;
#define lg long long
const lg N = 2e5+5;
vector<lg> adj[N], path;
lg dist[N], mxmnode, vis[N];
void dfs(lg src, lg par = -1, lg d = 1)
{
path.push_back(src);
vis[src] = true;
dist[src] = d;
if(dist[src] > dist[mxmnode])
{
mxmnode = src;
}
for(auto it : adj[src])
{
if(it == par) continue;
dfs(it, src, d+1);
}
return;
}
int main()
{
lg n, m;
cin >> n >> m;
for(int i = 0; i < m; i++)
{
lg u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
lg ans = 0;
for(int i = 1; i <= n; i++)
{
if(vis[i]) continue;
path.clear();
dfs(i, -1);
for(auto it : path) dist[it] = 0;
path.clear();
dfs(mxmnode, -1);
ans += dist[mxmnode];
mxmnode = 0;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
7116 KB |
Output is correct |
2 |
Correct |
19 ms |
8408 KB |
Output is correct |
3 |
Correct |
33 ms |
9324 KB |
Output is correct |
4 |
Correct |
35 ms |
10708 KB |
Output is correct |
5 |
Correct |
59 ms |
11356 KB |
Output is correct |
6 |
Correct |
54 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
17612 KB |
Output is correct |
2 |
Correct |
5 ms |
6492 KB |
Output is correct |
3 |
Correct |
10 ms |
7240 KB |
Output is correct |
4 |
Correct |
14 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6232 KB |
Output is correct |
2 |
Correct |
1 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
7 ms |
7000 KB |
Output is correct |
6 |
Correct |
12 ms |
8028 KB |
Output is correct |
7 |
Correct |
20 ms |
9044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5980 KB |
Output is correct |
2 |
Correct |
1 ms |
5980 KB |
Output is correct |
3 |
Correct |
1 ms |
5980 KB |
Output is correct |
4 |
Correct |
1 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
5980 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5976 KB |
Output is correct |
9 |
Correct |
2 ms |
5976 KB |
Output is correct |
10 |
Correct |
2 ms |
5980 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
7116 KB |
Output is correct |
2 |
Correct |
19 ms |
8408 KB |
Output is correct |
3 |
Correct |
33 ms |
9324 KB |
Output is correct |
4 |
Correct |
35 ms |
10708 KB |
Output is correct |
5 |
Correct |
59 ms |
11356 KB |
Output is correct |
6 |
Correct |
54 ms |
12280 KB |
Output is correct |
7 |
Correct |
52 ms |
17612 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
10 ms |
7240 KB |
Output is correct |
10 |
Correct |
14 ms |
7772 KB |
Output is correct |
11 |
Correct |
1 ms |
6232 KB |
Output is correct |
12 |
Correct |
1 ms |
5980 KB |
Output is correct |
13 |
Correct |
1 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5980 KB |
Output is correct |
15 |
Correct |
7 ms |
7000 KB |
Output is correct |
16 |
Correct |
12 ms |
8028 KB |
Output is correct |
17 |
Correct |
20 ms |
9044 KB |
Output is correct |
18 |
Correct |
2 ms |
5980 KB |
Output is correct |
19 |
Correct |
1 ms |
5980 KB |
Output is correct |
20 |
Correct |
1 ms |
5980 KB |
Output is correct |
21 |
Correct |
1 ms |
5980 KB |
Output is correct |
22 |
Correct |
2 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
2 ms |
5976 KB |
Output is correct |
26 |
Correct |
2 ms |
5976 KB |
Output is correct |
27 |
Correct |
2 ms |
5980 KB |
Output is correct |
28 |
Correct |
2 ms |
5980 KB |
Output is correct |
29 |
Correct |
66 ms |
12328 KB |
Output is correct |
30 |
Correct |
11 ms |
8284 KB |
Output is correct |
31 |
Correct |
37 ms |
10584 KB |
Output is correct |
32 |
Correct |
22 ms |
9048 KB |
Output is correct |
33 |
Correct |
55 ms |
10836 KB |
Output is correct |
34 |
Correct |
35 ms |
9528 KB |
Output is correct |
35 |
Correct |
40 ms |
10580 KB |
Output is correct |
36 |
Correct |
40 ms |
10708 KB |
Output is correct |
37 |
Correct |
50 ms |
10888 KB |
Output is correct |
38 |
Correct |
50 ms |
11464 KB |
Output is correct |
39 |
Correct |
43 ms |
10780 KB |
Output is correct |