Submission #580490

# Submission time Handle Problem Language Result Execution time Memory
580490 2022-06-21T10:41:50 Z FatihSolak Shymbulak (IZhO14_shymbulak) C++17
0 / 100
1500 ms 8476 KB
#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
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4948 KB Output is correct
2 Correct 12 ms 4968 KB Output is correct
3 Incorrect 20 ms 5052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1582 ms 8476 KB Time limit exceeded
2 Halted 0 ms 0 KB -