#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 100000
//para el mejor
#define nod first
#define prof second
lli a,b,n,m,res;
lli vis[MAX+2];
vector<lli> hijos[MAX+2];
pll mejor;
void dfs(lli pos, lli p) {
vis[pos] = 1;
if (mejor.prof < p) mejor = {pos,p};
for(auto h : hijos[pos]) {
if (vis[h] == 1) continue;
dfs(h,p+1);
}
}
lli cuenta(lli pos) {
lli sum = 0;
vis[pos] = 2;
for(auto h : hijos[pos]) {
if (vis[h] == 2) continue;
sum = max(sum, cuenta(h));
}
sum++;
return sum;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b;
hijos[a].push_back(b);
hijos[b].push_back(a);
}
rep(i,1,n) {
if (vis[i] > 0) continue;
mejor = {0,0};
dfs(i,1);
res += cuenta(mejor.nod);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3500 KB |
Output is correct |
2 |
Correct |
13 ms |
4544 KB |
Output is correct |
3 |
Correct |
16 ms |
5436 KB |
Output is correct |
4 |
Correct |
24 ms |
6376 KB |
Output is correct |
5 |
Correct |
22 ms |
7400 KB |
Output is correct |
6 |
Correct |
33 ms |
8276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
12420 KB |
Output is correct |
2 |
Correct |
4 ms |
3204 KB |
Output is correct |
3 |
Correct |
6 ms |
3860 KB |
Output is correct |
4 |
Correct |
7 ms |
4456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2680 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
4 ms |
3408 KB |
Output is correct |
6 |
Correct |
6 ms |
4180 KB |
Output is correct |
7 |
Correct |
12 ms |
4992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2684 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2676 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2684 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 |
6 ms |
3500 KB |
Output is correct |
2 |
Correct |
13 ms |
4544 KB |
Output is correct |
3 |
Correct |
16 ms |
5436 KB |
Output is correct |
4 |
Correct |
24 ms |
6376 KB |
Output is correct |
5 |
Correct |
22 ms |
7400 KB |
Output is correct |
6 |
Correct |
33 ms |
8276 KB |
Output is correct |
7 |
Correct |
32 ms |
12420 KB |
Output is correct |
8 |
Correct |
4 ms |
3204 KB |
Output is correct |
9 |
Correct |
6 ms |
3860 KB |
Output is correct |
10 |
Correct |
7 ms |
4456 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2680 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
6 ms |
4180 KB |
Output is correct |
17 |
Correct |
12 ms |
4992 KB |
Output is correct |
18 |
Correct |
2 ms |
2684 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2684 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2676 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2684 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 |
27 ms |
8260 KB |
Output is correct |
30 |
Correct |
12 ms |
4492 KB |
Output is correct |
31 |
Correct |
18 ms |
7316 KB |
Output is correct |
32 |
Correct |
14 ms |
5332 KB |
Output is correct |
33 |
Correct |
24 ms |
7936 KB |
Output is correct |
34 |
Correct |
16 ms |
6024 KB |
Output is correct |
35 |
Correct |
21 ms |
7544 KB |
Output is correct |
36 |
Correct |
35 ms |
6724 KB |
Output is correct |
37 |
Correct |
23 ms |
7884 KB |
Output is correct |
38 |
Correct |
28 ms |
7400 KB |
Output is correct |
39 |
Correct |
23 ms |
7628 KB |
Output is correct |