#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)
{
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
3284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
13596 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
10 ms |
3364 KB |
Output is correct |
4 |
Correct |
13 ms |
3872 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 |
6 ms |
3236 KB |
Output is correct |
6 |
Correct |
11 ms |
3936 KB |
Output is correct |
7 |
Correct |
17 ms |
4812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
3284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |