제출 #1340663

#제출 시각아이디문제언어결과실행 시간메모리
1340663kawhietHotspot (NOI17_hotspot)C++20
38 / 100
3 ms580 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

constexpr int N = 5001;

vector<int> d;
vector<vector<int>> g;

void bfs(int u) {
    fill(d.begin(), d.end(), -1);
    queue<int> q;
    q.push(u);
    d[u] = 0;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (auto y : g[x]) {
            if (d[y] == -1) {
                d[y] = d[x] + 1;
                q.push(y);
            }
        }
    }
}

int dist;
vector<bool> vis;
vector<int> x, y, ways;

void go(int st) {
    fill(vis.begin(), vis.end(), false);
    fill(ways.begin(), ways.end(), 0);
    queue<int> q;
    q.push(st);
    vis[st] = 1;
    ways[st] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto v : g[u]) {
            if (!vis[v] && x[v] + y[v] == dist) {
                if (!vis[v]) {
                    vis[v] = 1;
                    q.push(v);
                }
                ways[v] += ways[u];
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    d.resize(n);
    g.resize(n);
    vis.resize(n);
    ways.resize(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<long double> ans(n);
    int k;
    cin >> k;
    while (k--) {
        int a, b;
        cin >> a >> b;
        bfs(a); x = d;
        bfs(b); y = d;
        dist = x[b];
        go(a);
        int tot = ways[b];
        for (int i = 0; i < n; i++) {
            if (x[i] + y[i] == dist) {
                ans[i] += (long double)(tot) / (long double)(ways[i]);
            }
        }
    }
    long double mx = ranges::max(ans);
    for (int i = 0; i < n; i++) {
        if (ans[i] == mx) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...