답안 #1105417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105417 2024-10-26T10:00:29 Z minhvule Hotspot (NOI17_hotspot) C++17
100 / 100
1078 ms 1524 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define freo(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#define FOR(i, a, b) for(int i=(a),_b = (b); i<=_b; i++)
#define FORD(i, a, b) for(int i=(a),_b = (b); i>=_b; i--)
#define pii pair<int, int>
using namespace std;

const int N = 5e3 + 5;
int n, m, k, pa[N], pb[N], da[N], db[N];
vector<int> g[N];
double sum[N];

void dijkstra(int u, int d[], int pa[]) {
    priority_queue<pii, vector<pii>, greater<pii>> pq; // Use a min-heap for Dijkstra
    d[u] = 0;
    pq.push({0, u});
    while (!pq.empty()) {
        pii top = pq.top();
        pq.pop();
        int u = top.second;
        if (top.first > d[u]) continue;
        for (int v : g[u]) {
            if (d[v] > d[u] + 1) {
                d[v] = d[u] + 1;
                pa[v] = pa[u]; // Carry the path count from u
                pq.push({d[v], v});
            } else if (d[v] == d[u] + 1) {
                pa[v] += pa[u]; // Accumulate path counts
            }
        }
    }
}

void sub6() {
    FOR(i, 1, m) {
        int u, v; 
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    cin >> k;
    FOR(i, 1, k) {
        int a, b; 
        cin >> a >> b;
        
        FOR(i, 0, n) 
            da[i] = db[i] = INT_MAX, pa[i] = pb[i] = 1; // Initialize distance and path counts

        dijkstra(a, da, pa);
        dijkstra(b, db, pb);

        FOR(u, 0, n) 
            if (da[u] + db[u] == da[b]) {
                sum[u] += (pa[u] * pb[u] * 1.0) / pa[b];
            }
    }
    
    int ans = 0;
    FOR(i, 0, n) 
        if (sum[i] > sum[ans]) 
            ans = i;

    cout << ans;
}

void solve() {
    cin >> n >> m;
    sub6();
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout.tie(nullptr);
    freo("TRAINCENTRE");
    solve();
    return 0;
}

Compilation message

hotspot.cpp: In function 'int32_t main()':
hotspot.cpp:4:55: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define freo(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:77:5: note: in expansion of macro 'freo'
   77 |     freo("TRAINCENTRE");
      |     ^~~~
hotspot.cpp:4:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define freo(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:77:5: note: in expansion of macro 'freo'
   77 |     freo("TRAINCENTRE");
      |     ^~~~
# 결과 실행 시간 메모리 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 592 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 592 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 764 KB Output is correct
13 Correct 1 ms 592 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 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 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 592 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 764 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 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 6 ms 592 KB Output is correct
25 Correct 9 ms 592 KB Output is correct
26 Correct 10 ms 592 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 8 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 592 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 764 KB Output is correct
13 Correct 1 ms 592 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 6 ms 848 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 5 ms 848 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 592 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 764 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 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 6 ms 592 KB Output is correct
25 Correct 9 ms 592 KB Output is correct
26 Correct 10 ms 592 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 8 ms 592 KB Output is correct
29 Correct 2 ms 764 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 6 ms 848 KB Output is correct
32 Correct 4 ms 592 KB Output is correct
33 Correct 5 ms 848 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 52 ms 848 KB Output is correct
37 Correct 190 ms 848 KB Output is correct
38 Correct 1078 ms 1360 KB Output is correct
39 Correct 521 ms 1360 KB Output is correct
40 Correct 167 ms 848 KB Output is correct
41 Correct 715 ms 1496 KB Output is correct
42 Correct 726 ms 1524 KB Output is correct
43 Correct 68 ms 848 KB Output is correct
44 Correct 53 ms 848 KB Output is correct