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>
#define N 200005
using namespace std;
vector<int> adj[N];
void solve(){
int n;
cin >> n;
for(int i = 1;i<=n;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int ans1 = 0,ans2 = 0;
for(int i = 1;i<=n;i++){
vector<int> d(n+1,-1);
queue<int> q;
q.push(i);
d[i] = 0;
while(q.size()){
auto tp = q.front();
q.pop();
for(auto u:adj[tp]){
if(d[u] == -1){
q.push(u);
d[u] = d[tp] + 1;
}
}
}
for(int j = 1;j<=n;j++){
if(d[j] > ans1){
ans1 = d[j];
ans2 = 0;
}
if(d[j] == ans1)ans2++;
}
}
cout << ans2/2;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |