Submission #580490

#TimeUsernameProblemLanguageResultExecution timeMemory
580490FatihSolakShymbulak (IZhO14_shymbulak)C++17
0 / 100
1582 ms8476 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...