#include<bits/stdc++.h>
using namespace std;
#define int long long
long long n, m, x, y, dis[100001], maxi, ans = 0;
vector<int> vec[100001];
bool check[100001];
void dfs(int x, int p, int h)
{
check[x] = true;
for(int c : vec[x]) if(c != p) dfs(c, x, h + 1);
maxi = max(maxi, h);
}
signed main()
{
cin >> n >> m;
while(m--)
{
cin >> x >> y;
vec[x].push_back(y);
vec[y].push_back(x);
}
for(int i = 1; i <= n; ++i)
{
if(!check[i])
{
check[i] = true;
priority_queue<int> pri;
for(int c : vec[i])
{
maxi = -1;
dfs(c, i, 1);
pri.push(maxi);
}
int cnt = 0;
while(!pri.empty() && cnt < 2)
{
ans += pri.top();
++cnt;
pri.pop();
}
++ans;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
12168 KB |
Output is correct |
2 |
Correct |
5 ms |
3156 KB |
Output is correct |
3 |
Correct |
10 ms |
3492 KB |
Output is correct |
4 |
Correct |
14 ms |
3972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
7 ms |
3412 KB |
Output is correct |
6 |
Correct |
11 ms |
4180 KB |
Output is correct |
7 |
Correct |
17 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |