#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 && !check[c]) 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)
{
priority_queue<int> pri;
if(!check[i])
{
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14744 KB |
Output is correct |
2 |
Correct |
5 ms |
3060 KB |
Output is correct |
3 |
Correct |
10 ms |
3568 KB |
Output is correct |
4 |
Correct |
14 ms |
4128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2656 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
7 ms |
3516 KB |
Output is correct |
6 |
Correct |
12 ms |
4260 KB |
Output is correct |
7 |
Correct |
17 ms |
5132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |