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;
using ll = long long;
void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";}
vector <int> adj[100005];
int point = 1;
int maxi = 1;
vector <bool> vis(100005);
void dfs(int i,int p,int cur){
vis[i]=true;
if(cur > maxi){
maxi = cur;
point = i;
}
for(int j : adj[i]){
if(j != p){
dfs(j,i,cur+1);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,m;
cin >> n >> m;
for(int i = 0;i < m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int res = 0;
for(int i = 1;i <= n;i++){
if(!vis[i]){
point = i;
dfs(i,-1,1);
dfs(point,-1,1);
res += maxi;
maxi = 1;
}
}
cout << res << "\n";
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... |