Submission #949937

# Submission time Handle Problem Language Result Execution time Memory
949937 2024-03-19T23:31:08 Z efishel Hotspot (NOI17_hotspot) C++17
100 / 100
413 ms 2644 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dou = double;
using vll = vector <ll>;

const ll MAXN = 5E3+16;
vll adj[MAXN];
vll radj[MAXN];

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        ll u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll k;
    cin >> k;
    vector <dou> vals(n, 0);
    for (ll i = 0; i < k; i++) {
        ll s, t;
        cin >> s >> t;
        for (ll j = 0; j < MAXN; j++) radj[j].clear();
        vll dp1(n, 0); // ways to reach i from s (s -> i)
        vll dp2(n, 0); // ways to reach t from i (i -> t)
        vll dis(n, -16);
        {vector <bool> vis(n, false);
        queue <ll> q;
        dp1[s] = 1;
        q.push(s);
        dis[s] = 0;
        vis[s] = true;
        while (q.size()) { // count shortest paths
            ll u = q.front(); q.pop();
            // cerr << u << '\n';
            for (ll v : adj[u]) {
                if (vis[v] && dis[u]+1 != dis[v]) continue;
                // cerr << "   " << v << '\n';
                dp1[v] += dp1[u];
                radj[v].push_back(u);
                if (vis[v]) continue;
                // cerr << "   new\n";
                q.push(v);
                dis[v] = dis[u]+1;
                vis[v] = true;
            }
        }}
        // // for (ll i : dp1) cerr << i << ' '; cerr << '\n';
        {vector <bool> vis(n, false); // travel from t to s adding values
        queue <ll> q;
        q.push(t);
        assert(dp1[t] > 0);
        dp2[t] = 1;
        while (q.size()) {
            ll u = q.front(); q.pop();
            // cerr << u << '\n';
            vals[u] += dou(dp1[u] * dp2[u]) / dou(dp1[t] * dp2[t]);
            for (ll v : radj[u]) {
                if (dis[u]-1 != dis[v]) continue;
                // cerr << "   " << v << '\n';
                dp2[v] += dp2[u];
                if (vis[v]) continue;
                // cerr << "   new\n";
                q.push(v);
                vis[v] = true;
            }
        }}
        // // for (ll i : dp2) cerr << i << ' '; cerr << '\n';
    }
    // cerr << fixed << setprecision(6);
    // for (dou i : vals) cerr << i << ' ';
    // cerr << '\n';
    cout << max_element(vals.begin(), vals.end()) - vals.begin() << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 3 ms 1112 KB Output is correct
18 Correct 2 ms 800 KB Output is correct
19 Correct 3 ms 820 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 3 ms 1112 KB Output is correct
32 Correct 2 ms 800 KB Output is correct
33 Correct 3 ms 820 KB Output is correct
34 Correct 2 ms 1112 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 33 ms 1116 KB Output is correct
37 Correct 82 ms 1348 KB Output is correct
38 Correct 413 ms 2436 KB Output is correct
39 Correct 283 ms 1884 KB Output is correct
40 Correct 43 ms 1112 KB Output is correct
41 Correct 253 ms 2644 KB Output is correct
42 Correct 348 ms 2536 KB Output is correct
43 Correct 20 ms 1116 KB Output is correct
44 Correct 17 ms 1368 KB Output is correct