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 rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3HspL4A;
int n,m;
cin>>n>>m;
vec(vi) adj(n);
rep(i,m){
int u,v;
cin>>u>>v;
u-=1,v-=1;
adj[u].pb(v);
adj[v].pb(u);
}
vi usd(n,0);
int now=0;
auto dfs=[&](auto self,int v)->int{
usd[v]=1;
pii p={0,0};
for(auto u:adj[v]){
if(!usd[u]){
int val=self(self,u);
if(val>p.fi){
p.se=p.fi;
p.fi=val;
}else if(val>p.se){
p.se=val;
}
}
}
now=max(now,p.fi+p.se+1);
return p.fi+1;
};
int ans=0;
rep(v,n)if(!usd[v]){
now=0;
dfs(dfs,v);
ans+=now;
}
print(ans);
//
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... |