This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
long long n, m, x, y, dis[100001], ans = 0;
vector<int> vec[100001];
bool check[100001];
pair<int, int> maxi;
void dfs(int x, int p, int h)
{
check[x] = true;
for(int c : vec[x]) if(c != p) dfs(c, x, h + 1);
if(maxi.first < h) maxi = {h, x};
}
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;
maxi = {-1, -1};
dfs(i, 0, 1);
dfs(maxi.second, 0, 1);
ans += maxi.first;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |