# 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;
int n, m, vv, uu, cur;
vector <int> g[maxn];
bool used[maxn];
void dfs (int v, int pa, int d, bool tp)
{
if (d > cur)
{
cur = d;
if (!tp)
vv = v;
else
uu = v;
}
used[v] = 1;
for (int to : g[v])
{
if (to != pa)
{
dfs(to, v, d + 1, tp);
}
}
}
void ma1n ()
{
cin >> n >> m;
for (int i = 1, u, v; i <= m; ++i)
{
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
if (!used[i])
{
cur = 1;
dfs(i, i, 1, 0);
cur = 1;
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 |
3420 KB |
Output is correct |
2 |
Correct |
12 ms |
4096 KB |
Output is correct |
3 |
Correct |
19 ms |
4920 KB |
Output is correct |
4 |
Correct |
26 ms |
5612 KB |
Output is correct |
5 |
Correct |
35 ms |
6364 KB |
Output is correct |
6 |
Correct |
40 ms |
7152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
130 ms |
13284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2676 KB |
Output is correct |
2 |
Correct |
2 ms |
2680 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2684 KB |
Output is correct |
5 |
Incorrect |
179 ms |
3296 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3420 KB |
Output is correct |
2 |
Correct |
12 ms |
4096 KB |
Output is correct |
3 |
Correct |
19 ms |
4920 KB |
Output is correct |
4 |
Correct |
26 ms |
5612 KB |
Output is correct |
5 |
Correct |
35 ms |
6364 KB |
Output is correct |
6 |
Correct |
40 ms |
7152 KB |
Output is correct |
7 |
Incorrect |
130 ms |
13284 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |