Submission #37393

#TimeUsernameProblemLanguageResultExecution timeMemory
37393HardNutShymbulak (IZhO14_shymbulak)C++14
50 / 100
1500 ms8412 KiB
#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)

shymbulak.cpp: In function 'void bfs(int)':
shymbulak.cpp:30:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < g[u].size(); i++) {
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...