Submission #1105356

# Submission time Handle Problem Language Result Execution time Memory
1105356 2024-10-26T08:36:00 Z LTTrungCHL Hotspot (NOI17_hotspot) C++17
9 / 100
3 ms 8700 KB
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
vector <int> lg2;
//void MAKE_LOG_ARR(int n){
//    lg2.resize(n + 3);
//    for (int i = 1;i <= n;++i){
//        lg2[i] = __lg(i);
//    }
//}
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, m;
pair <int ,int> disa[N], disb[N];
vector <int> adj[N];
queue <int> q;
pair <long double ,int> e[N];
void solve(){
    cin >> n >> m;
    for (int i = 0;i < n;++i){
        e[i].S = i;
    }
    for (int i = 1;i <= m;++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int k;
    cin >> k;
    for (int ik = 1;ik <= k;++ik){
        int a, b;
        cin >> a >> b;
        for (int i = 0;i < n;++i){
            disa[i] = {oo, 0};
            disb[i] = {oo, 0};
        }
        disa[a] = {1,1};
        disb[b] = {1,1};
        q.push(a);
        while (!q.empty()){
            int u = q.front();
            q.pop();
            for (int v : adj[u]){
                if (disa[u].F + 1 == disa[v].F){
                    disa[v].S += disa[u].S;
                }
                if (disa[u].F + 1 < disa[v].F){
                    disa[v].F = disa[u].F + 1;
                    disa[v].S = disa[u].S;
                    q.push(v);
                }
            }
        }
        q.push(b);
        while (!q.empty()){
            int u = q.front();
            q.pop();
            for (int v : adj[u]){
                if (disb[u].F + 1 == disb[v].F){
                    disb[v].S += disb[u].S;
                }
                if (disb[u].F + 1 < disb[v].F){
                    disb[v].F = disb[u].F + 1;
                    disb[v].S = disb[u].S;
                    q.push(v);
                }
            }
        }
//        cout << a <<" "<< b <<" : "<< disa[b].F <<"\n";
        for (int i = 0;i < n;++i){
            int mia = oo;
            int mib = oo;
            for (int v : adj[i]){
                mia = min(mia, disa[v].F);
                mib = min(mib, disb[v].F);
            }
//            cout << i <<" "<< mia <<" "<< mib <<"\n";
            if (mia + mib + 1 != disa[b].F) continue;
            int suma = 0;
            int sumb = 0;
            for (int v : adj[i]){
                if (disa[v].F == mia){
                    suma += disa[v].S;
                }
                if (disb[v].F == mib){
                    sumb += disb[v].S;
                }
            }
//            cout << a << " "<< b <<" "<<i <<" : "<< disa[b].S <<" "<< suma <<" "<< sumb<<"\n";
            long double tmp =(suma * sumb);
            long double tmp2 = disa[b].S;
            e[i].F += tmp/ tmp2;
        }
    }
//    for (int i = 0;i < n;++i){
//        cout << e[i].F <<"\n";
//    }
    sort(e ,e + n);
    cout << e[n - 1].S;
    return;
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    if (fopen("ltt.inp", "r")){
        freopen("ltt.inp", "r", stdin);
        freopen("ltt.out", "w", stdout);
    }
//    int t;
//    cin >> t;
//    while(t--){
    solve();
//    }
    return 0;
}






Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen("ltt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen("ltt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8676 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 2 ms 8528 KB Output is correct
12 Correct 2 ms 8528 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 2 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
8 Incorrect 2 ms 8528 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8676 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 2 ms 8528 KB Output is correct
12 Correct 2 ms 8528 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 2 ms 8528 KB Output is correct
15 Incorrect 2 ms 8528 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8676 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 2 ms 8528 KB Output is correct
12 Correct 2 ms 8528 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 2 ms 8528 KB Output is correct
15 Incorrect 3 ms 8528 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8636 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8676 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 2 ms 8528 KB Output is correct
12 Correct 2 ms 8528 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 2 ms 8528 KB Output is correct
15 Incorrect 2 ms 8528 KB Output isn't correct
16 Halted 0 ms 0 KB -