#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e5 + 50;
const ll Mod = 1e9 + 7;
ll n, m;
bool mark[N];
vector<int> adj[N];
pii far(int v, int p = 0, int h = 0){
mark[v] = true;
pii out = Mp(h, v);
for(int u: adj[v]){
if(u == p) continue;
out = max(out, far(u, v, h+1));
}
return out;
}
int main(){
fast_io;
cin >> n >> m;
int u, v;
for(int i = 1; i <= m; i++){
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
ll res = 0;
for(int i = 1; i <= n; i++){
if(!mark[i]){
v = far(i).S;
res += far(v).F + 1;
}
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3420 KB |
Output is correct |
2 |
Correct |
10 ms |
4188 KB |
Output is correct |
3 |
Correct |
13 ms |
4956 KB |
Output is correct |
4 |
Correct |
18 ms |
5724 KB |
Output is correct |
5 |
Correct |
22 ms |
6328 KB |
Output is correct |
6 |
Correct |
25 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
11356 KB |
Output is correct |
2 |
Correct |
3 ms |
3084 KB |
Output is correct |
3 |
Correct |
5 ms |
3796 KB |
Output is correct |
4 |
Correct |
7 ms |
4108 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 |
3 ms |
3420 KB |
Output is correct |
6 |
Correct |
6 ms |
4084 KB |
Output is correct |
7 |
Correct |
7 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 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 |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3420 KB |
Output is correct |
2 |
Correct |
10 ms |
4188 KB |
Output is correct |
3 |
Correct |
13 ms |
4956 KB |
Output is correct |
4 |
Correct |
18 ms |
5724 KB |
Output is correct |
5 |
Correct |
22 ms |
6328 KB |
Output is correct |
6 |
Correct |
25 ms |
7512 KB |
Output is correct |
7 |
Correct |
24 ms |
11356 KB |
Output is correct |
8 |
Correct |
3 ms |
3084 KB |
Output is correct |
9 |
Correct |
5 ms |
3796 KB |
Output is correct |
10 |
Correct |
7 ms |
4108 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 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 |
3420 KB |
Output is correct |
16 |
Correct |
6 ms |
4084 KB |
Output is correct |
17 |
Correct |
7 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
2648 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 |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
28 ms |
7296 KB |
Output is correct |
30 |
Correct |
6 ms |
3932 KB |
Output is correct |
31 |
Correct |
24 ms |
6568 KB |
Output is correct |
32 |
Correct |
10 ms |
4700 KB |
Output is correct |
33 |
Correct |
28 ms |
6996 KB |
Output is correct |
34 |
Correct |
15 ms |
5468 KB |
Output is correct |
35 |
Correct |
18 ms |
6748 KB |
Output is correct |
36 |
Correct |
20 ms |
5852 KB |
Output is correct |
37 |
Correct |
22 ms |
7004 KB |
Output is correct |
38 |
Correct |
26 ms |
6492 KB |
Output is correct |
39 |
Correct |
21 ms |
6748 KB |
Output is correct |