Submission #1105394

# Submission time Handle Problem Language Result Execution time Memory
1105394 2024-10-26T09:28:43 Z TVSown Hotspot (NOI17_hotspot) C++17
100 / 100
622 ms 49340 KB
///*** Sown_Vipro ***///
/// ->GIAI BA QUOC GIA<- ///

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = a; i >= b; --i)
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
#define szz(s) int(s.size())
const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
int n, m, k;
vector<int> e[N];
vector<long long> dA(N), dB(N);
vector<int> cA(N), cB(N);
double ans[N];

void bfs(int s, vector<long long> &d, vector<int> &c){
    FOR(u, 0, n - 1){
        d[u] = 1e18;
        c[u] = 0;
    }
    d[s] = 0;
    c[s] = 1;
    queue<int> q;
    q.push(s);

    while(szz(q)){
        int u = q.front(); q.pop();
        for(int v : e[u]){
            if(d[u] + 1 < d[v]){
                d[v] = d[u] + 1;
                c[v] = c[u];
                q.push(v);
            }else if(d[u] + 1 == d[v]){
                c[v] += c[u];
            }
        }
    }
}

void solve(){
    cin >> n >> m;
    FOR(i, 1, m){
        int u, v; cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }
    cin >> k;
    FOR(i, 1, k){

        int a, b; cin >> a >> b;
        bfs(a, dA, cA);
        bfs(b, dB, cB);
//        cout << a << " " << b << " " << cA[b] << "\n";
        FOR(u, 0, n - 1){
            if(dA[u] + dB[u] == dA[b]){
//                cout << u << " " << a << " " << b << " " << cA[u] << " " << cB[u] << "\n";
                long double c = cA[u] * cB[u];
                ans[u] += c / cA[b];
            }
        }
    }

    long double r1 = 0;
    int r2 = 0;
    FOR(u, 0, n - 1){
//        cout << u << " " << ans[u] << "\n";
        if(ans[u] > r1){
            r1 = ans[u];
            r2 = u;
        }
    }

    cout << r2;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    inp("in.txt");
    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:16:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
hotspot.cpp:89:5: note: in expansion of macro 'inp'
   89 |     inp("in.txt");
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
8 Correct 12 ms 48720 KB Output is correct
9 Correct 11 ms 48720 KB Output is correct
10 Correct 11 ms 48860 KB Output is correct
11 Correct 11 ms 48736 KB Output is correct
12 Correct 11 ms 48720 KB Output is correct
13 Correct 10 ms 48720 KB Output is correct
14 Correct 11 ms 48864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
8 Correct 12 ms 48720 KB Output is correct
9 Correct 13 ms 48872 KB Output is correct
10 Correct 15 ms 48720 KB Output is correct
11 Correct 13 ms 48720 KB Output is correct
12 Correct 12 ms 48720 KB Output is correct
13 Correct 11 ms 48868 KB Output is correct
14 Correct 12 ms 48720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
8 Correct 12 ms 48720 KB Output is correct
9 Correct 11 ms 48720 KB Output is correct
10 Correct 11 ms 48860 KB Output is correct
11 Correct 11 ms 48736 KB Output is correct
12 Correct 11 ms 48720 KB Output is correct
13 Correct 10 ms 48720 KB Output is correct
14 Correct 11 ms 48864 KB Output is correct
15 Correct 12 ms 48720 KB Output is correct
16 Correct 13 ms 48872 KB Output is correct
17 Correct 15 ms 48720 KB Output is correct
18 Correct 13 ms 48720 KB Output is correct
19 Correct 12 ms 48720 KB Output is correct
20 Correct 11 ms 48868 KB Output is correct
21 Correct 12 ms 48720 KB Output is correct
22 Correct 13 ms 48720 KB Output is correct
23 Correct 12 ms 48720 KB Output is correct
24 Correct 13 ms 48736 KB Output is correct
25 Correct 14 ms 48968 KB Output is correct
26 Correct 14 ms 48720 KB Output is correct
27 Correct 11 ms 48892 KB Output is correct
28 Correct 14 ms 48720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
8 Correct 12 ms 48720 KB Output is correct
9 Correct 11 ms 48720 KB Output is correct
10 Correct 11 ms 48860 KB Output is correct
11 Correct 11 ms 48736 KB Output is correct
12 Correct 11 ms 48720 KB Output is correct
13 Correct 10 ms 48720 KB Output is correct
14 Correct 11 ms 48864 KB Output is correct
15 Correct 13 ms 48976 KB Output is correct
16 Correct 12 ms 48976 KB Output is correct
17 Correct 14 ms 48968 KB Output is correct
18 Correct 13 ms 49004 KB Output is correct
19 Correct 15 ms 48976 KB Output is correct
20 Correct 13 ms 48832 KB Output is correct
21 Correct 12 ms 48720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48720 KB Output is correct
2 Correct 11 ms 48720 KB Output is correct
3 Correct 11 ms 48720 KB Output is correct
4 Correct 11 ms 48720 KB Output is correct
5 Correct 11 ms 48720 KB Output is correct
6 Correct 13 ms 48720 KB Output is correct
7 Correct 11 ms 48720 KB Output is correct
8 Correct 12 ms 48720 KB Output is correct
9 Correct 11 ms 48720 KB Output is correct
10 Correct 11 ms 48860 KB Output is correct
11 Correct 11 ms 48736 KB Output is correct
12 Correct 11 ms 48720 KB Output is correct
13 Correct 10 ms 48720 KB Output is correct
14 Correct 11 ms 48864 KB Output is correct
15 Correct 12 ms 48720 KB Output is correct
16 Correct 13 ms 48872 KB Output is correct
17 Correct 15 ms 48720 KB Output is correct
18 Correct 13 ms 48720 KB Output is correct
19 Correct 12 ms 48720 KB Output is correct
20 Correct 11 ms 48868 KB Output is correct
21 Correct 12 ms 48720 KB Output is correct
22 Correct 13 ms 48720 KB Output is correct
23 Correct 12 ms 48720 KB Output is correct
24 Correct 13 ms 48736 KB Output is correct
25 Correct 14 ms 48968 KB Output is correct
26 Correct 14 ms 48720 KB Output is correct
27 Correct 11 ms 48892 KB Output is correct
28 Correct 14 ms 48720 KB Output is correct
29 Correct 13 ms 48976 KB Output is correct
30 Correct 12 ms 48976 KB Output is correct
31 Correct 14 ms 48968 KB Output is correct
32 Correct 13 ms 49004 KB Output is correct
33 Correct 15 ms 48976 KB Output is correct
34 Correct 13 ms 48832 KB Output is correct
35 Correct 12 ms 48720 KB Output is correct
36 Correct 63 ms 49252 KB Output is correct
37 Correct 137 ms 48976 KB Output is correct
38 Correct 622 ms 49340 KB Output is correct
39 Correct 360 ms 49232 KB Output is correct
40 Correct 79 ms 48976 KB Output is correct
41 Correct 402 ms 49340 KB Output is correct
42 Correct 506 ms 49232 KB Output is correct
43 Correct 41 ms 48976 KB Output is correct
44 Correct 35 ms 48976 KB Output is correct