# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define pii pair <int, int>
# define pll pair <ll, ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 1e5 + 125;
const ll maxl = 20 + 0;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
using namespace std;
ll n, m, vv, uu, cur;
vector <ll> g[maxn];
bool used[maxn];
void dfs (ll v, ll pa, ll d, bool tp)
{
if (d >= cur)
{
cur = d;
if (!tp)
vv = v;
else
uu = v;
}
used[v] = 1;
for (ll to : g[v])
{
if (to != pa)
{
dfs(to, v, d + 1, tp);
}
}
}
void ma1n ()
{
cin >> n >> m;
for (ll i = 1, u, v; i <= m; ++i)
{
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
ll ans = 0;
for (ll i = 1; i <= n; ++i)
{
if (!used[i])
{
cur = 0;
dfs(i, i, 1, 0);
cur = 0;
dfs(vv, vv, 1, 1);
ans += cur;
// cout << vv << ' ' << uu << nl;
}
}
cout << ans << nl;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; test++)
{
// cout << "Case " << test << ":" << nl;
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3284 KB |
Output is correct |
2 |
Correct |
11 ms |
3960 KB |
Output is correct |
3 |
Correct |
17 ms |
4564 KB |
Output is correct |
4 |
Correct |
21 ms |
5152 KB |
Output is correct |
5 |
Correct |
30 ms |
5868 KB |
Output is correct |
6 |
Correct |
40 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
12108 KB |
Output is correct |
2 |
Correct |
4 ms |
3028 KB |
Output is correct |
3 |
Correct |
9 ms |
3464 KB |
Output is correct |
4 |
Correct |
7 ms |
3796 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 |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
8 ms |
3748 KB |
Output is correct |
7 |
Correct |
11 ms |
4320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 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 |
3 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3284 KB |
Output is correct |
2 |
Correct |
11 ms |
3960 KB |
Output is correct |
3 |
Correct |
17 ms |
4564 KB |
Output is correct |
4 |
Correct |
21 ms |
5152 KB |
Output is correct |
5 |
Correct |
30 ms |
5868 KB |
Output is correct |
6 |
Correct |
40 ms |
6492 KB |
Output is correct |
7 |
Correct |
27 ms |
12108 KB |
Output is correct |
8 |
Correct |
4 ms |
3028 KB |
Output is correct |
9 |
Correct |
9 ms |
3464 KB |
Output is correct |
10 |
Correct |
7 ms |
3796 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
4 ms |
3156 KB |
Output is correct |
16 |
Correct |
8 ms |
3748 KB |
Output is correct |
17 |
Correct |
11 ms |
4320 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 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 |
3 ms |
2644 KB |
Output is correct |
29 |
Correct |
41 ms |
6492 KB |
Output is correct |
30 |
Correct |
9 ms |
3540 KB |
Output is correct |
31 |
Correct |
24 ms |
5808 KB |
Output is correct |
32 |
Correct |
18 ms |
4384 KB |
Output is correct |
33 |
Correct |
28 ms |
6168 KB |
Output is correct |
34 |
Correct |
20 ms |
4820 KB |
Output is correct |
35 |
Correct |
24 ms |
5972 KB |
Output is correct |
36 |
Correct |
25 ms |
5364 KB |
Output is correct |
37 |
Correct |
30 ms |
6228 KB |
Output is correct |
38 |
Correct |
39 ms |
5836 KB |
Output is correct |
39 |
Correct |
26 ms |
6044 KB |
Output is correct |