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 <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 100000
//para el mejor
#define nod first
#define prof second
lli a,b,n,m,res;
lli vis[MAX+2];
vector<lli> hijos[MAX+2];
pll mejor;
void dfs(lli pos, lli p) {
vis[pos] = 1;
if (mejor.prof < p) mejor = {pos,p};
for(auto h : hijos[pos]) {
if (vis[h] == 1) continue;
dfs(h,p+1);
}
}
lli cuenta(lli pos) {
lli sum = 0;
vis[pos] = 2;
for(auto h : hijos[pos]) {
if (vis[h] == 2) continue;
sum = max(sum, cuenta(h));
}
sum++;
return sum;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b;
hijos[a].push_back(b);
hijos[b].push_back(a);
}
rep(i,1,n) {
if (vis[i] > 0) continue;
mejor = {0,0};
dfs(i,1);
res += cuenta(mejor.nod);
}
cout << res;
return 0;
}
# | 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... |