#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100001];
bool vis[100001]={false};
int again, maxdepth;
void dfs(int current, int past, int depth) {
vis[current]=true;
if(depth>maxdepth) {
maxdepth=depth;
again=current;
}
for(auto iter:adj[current]) {
if(iter != past) {
dfs(iter, current, depth+1);
}
}
}
int longest(int i) {
maxdepth=0;
dfs(i, -1, 1);
maxdepth=0;
dfs(again, -1, 1);
return maxdepth;
}
int main() {
int N,M,A,B;
cin >> N >> M;
for(int i=1; i<=M; i++) {
cin >> A >> B;
adj[A].push_back(B);
adj[B].push_back(A);
}
int sum=0;
for(int i=1; i<=N; i++) {
if(vis[i]==false) {
sum+=longest(i);
}
}
cout << sum << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
3192 KB |
Output is correct |
2 |
Correct |
19 ms |
3692 KB |
Output is correct |
3 |
Correct |
28 ms |
4276 KB |
Output is correct |
4 |
Correct |
48 ms |
4768 KB |
Output is correct |
5 |
Correct |
47 ms |
5424 KB |
Output is correct |
6 |
Correct |
58 ms |
5872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
10472 KB |
Output is correct |
2 |
Correct |
8 ms |
2972 KB |
Output is correct |
3 |
Correct |
14 ms |
3476 KB |
Output is correct |
4 |
Correct |
20 ms |
3752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
3084 KB |
Output is correct |
6 |
Correct |
17 ms |
3640 KB |
Output is correct |
7 |
Correct |
28 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
3192 KB |
Output is correct |
2 |
Correct |
19 ms |
3692 KB |
Output is correct |
3 |
Correct |
28 ms |
4276 KB |
Output is correct |
4 |
Correct |
48 ms |
4768 KB |
Output is correct |
5 |
Correct |
47 ms |
5424 KB |
Output is correct |
6 |
Correct |
58 ms |
5872 KB |
Output is correct |
7 |
Correct |
53 ms |
10472 KB |
Output is correct |
8 |
Correct |
8 ms |
2972 KB |
Output is correct |
9 |
Correct |
14 ms |
3476 KB |
Output is correct |
10 |
Correct |
20 ms |
3752 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
9 ms |
3084 KB |
Output is correct |
16 |
Correct |
17 ms |
3640 KB |
Output is correct |
17 |
Correct |
28 ms |
4188 KB |
Output is correct |
18 |
Correct |
3 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2668 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
56 ms |
5932 KB |
Output is correct |
30 |
Correct |
17 ms |
3540 KB |
Output is correct |
31 |
Correct |
59 ms |
5856 KB |
Output is correct |
32 |
Correct |
34 ms |
4172 KB |
Output is correct |
33 |
Correct |
74 ms |
5816 KB |
Output is correct |
34 |
Correct |
40 ms |
4612 KB |
Output is correct |
35 |
Correct |
65 ms |
5792 KB |
Output is correct |
36 |
Correct |
44 ms |
5084 KB |
Output is correct |
37 |
Correct |
52 ms |
5804 KB |
Output is correct |
38 |
Correct |
54 ms |
5444 KB |
Output is correct |
39 |
Correct |
62 ms |
5840 KB |
Output is correct |