| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 37393 | HardNut | Shymbulak (IZhO14_shymbulak) | C++14 | 1500 ms | 8412 KiB | 
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<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int N = 1e5 + 5;
typedef long long ll;
int n, ans, mx, d[N], ct[N];
vector<int> g[N];
bool used[N];
void bfs(int v) {
    queue<int> q;
    q.push(v);
    for (int i = 1; i <= n; i++) {
        used[i] = 0;
        ct[i] = 0;
    }
    d[v] = 0;
    used[v] = 1;
    ct[v] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = 0; i < g[u].size(); i++) {
            int to = g[u][i];
            if (!used[to]) {
                used[to] = 1;
                ct[to] = ct[u];
                d[to] = d[u] + 1;
                q.push(to);
            } else if (d[to] == d[u] + 1) {
                ct[to] += ct[u];
            }
        }
    }
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        bfs(i);
        for (int j = 1; j <= n; j++) {
            if (d[j] > mx) {
                mx = d[j];
                ans = 0;
            }
            if (d[j] == mx) {
                ans += ct[j];
            }
        }
    }
    cout << ans / 2;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
