답안 #1102946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102946 2024-10-19T09:11:36 Z Cam Hotspot (NOI17_hotspot) C++17
100 / 100
1055 ms 1104 KB
#include <bits/stdc++.h>
#define name "traincentre"
#define ll long long
#define db double
#define pb push_back
#define ii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define bit(x,i) (((x)>>(i))&1)
#define sz(s) (int)(s).size()
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=(a), _b=(b); i<=_b; i++)
#define repd(i,a,b) for(int i=(a), _b=(b); i>=_b; i--)
#define _unique(x) (x).resize(unique(all(x)) - (x).begin())

using namespace std;

const int N = 5e3 + 3;
const int inf = 1e9 + 7;
const int base = 31;
const double eps = 0.00000001;

int n, m, k;
int d[2][N];
db cnt[2][N], ans[N], res;
vector <int> a[N];

void dijkstra (int o, int s) {

    rep (i, 1, n) d[o][i] = inf, cnt[o][i] = 0;
    priority_queue <ii, vector <ii>, greater <ii> > q;
    q.push (mp (0, s)); d[o][s] = 0; cnt[o][s] = 1;

    while (sz (q)) {

        int u = q.top().se, du = q.top().fi; q.pop();
        if (du > d[o][u]) continue;
        for (int v : a[u]) {

            if (d[o][v] > d[o][u] + 1) {

                d[o][v] = d[o][u] + 1;
                q.push (mp (d[o][v], v));
                cnt[o][v] = cnt[o][u];
            }
            else if (d[o][v] == d[o][u] + 1) cnt[o][v] += cnt[o][u];
        }
    }
}
void solve (void) {

    cin >> n >> m;
    rep (i, 1, m) {

        int u, v; cin >> u >> v;
        u ++; v ++;
        a[u].pb (v); a[v].pb (u);
    }
    cin >> k;
    rep (i, 1, k) {

        int x, y;
        cin >> x >> y;
        x ++; y ++;
        dijkstra (0, x); dijkstra (1, y);
        rep (u, 1, n) if (d[0][u] + d[1][u] == d[0][y]) {

            db tmp = (db)(cnt[0][u] * cnt[1][u]);
            tmp = tmp / (db)cnt[0][y];
            ans[u] += tmp;
        }
    }
    int u = 1; res = ans[1];
    rep (i, 2, n) if (ans[i] > res) {

        res = ans[i];
        u = i;
    }
    cout << u - 1;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);

    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 760 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 756 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 760 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 756 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 3 ms 592 KB Output is correct
23 Correct 3 ms 592 KB Output is correct
24 Correct 5 ms 644 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 9 ms 656 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 7 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 760 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
19 Correct 5 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 760 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 756 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 3 ms 592 KB Output is correct
23 Correct 3 ms 592 KB Output is correct
24 Correct 5 ms 644 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 9 ms 656 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 7 ms 636 KB Output is correct
29 Correct 2 ms 764 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 5 ms 592 KB Output is correct
32 Correct 3 ms 592 KB Output is correct
33 Correct 5 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 54 ms 592 KB Output is correct
37 Correct 183 ms 848 KB Output is correct
38 Correct 1055 ms 1104 KB Output is correct
39 Correct 489 ms 1064 KB Output is correct
40 Correct 140 ms 876 KB Output is correct
41 Correct 705 ms 1104 KB Output is correct
42 Correct 739 ms 1104 KB Output is correct
43 Correct 60 ms 592 KB Output is correct
44 Correct 52 ms 592 KB Output is correct