답안 #1105370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105370 2024-10-26T08:43:09 Z LTTrungCHL Hotspot (NOI17_hotspot) C++17
100 / 100
733 ms 11600 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);
                }
            }
        }
        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);
            }
            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;
                }
            }
            long double tmp =(suma * sumb);
            long double tmp2 = disa[b].S;
            e[i].F += tmp/ tmp2;
        }
        e[a].F += 1;
        e[b].F += 1;
    }
    sort(e ,e + n);
    cout << e[n - 1].S;
    return;
}
signed 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:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen("ltt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen("ltt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 3 ms 10744 KB Output is correct
10 Correct 3 ms 10576 KB Output is correct
11 Correct 3 ms 10576 KB Output is correct
12 Correct 2 ms 10744 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 3 ms 10744 KB Output is correct
17 Correct 3 ms 10576 KB Output is correct
18 Correct 3 ms 10576 KB Output is correct
19 Correct 2 ms 10744 KB Output is correct
20 Correct 2 ms 10576 KB Output is correct
21 Correct 3 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 3 ms 10576 KB Output is correct
24 Correct 3 ms 10576 KB Output is correct
25 Correct 4 ms 10656 KB Output is correct
26 Correct 4 ms 10576 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 3 ms 10756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10576 KB Output is correct
15 Correct 3 ms 10832 KB Output is correct
16 Correct 2 ms 10832 KB Output is correct
17 Correct 5 ms 10832 KB Output is correct
18 Correct 3 ms 10832 KB Output is correct
19 Correct 5 ms 10832 KB Output is correct
20 Correct 3 ms 10832 KB Output is correct
21 Correct 2 ms 10744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10692 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 3 ms 10744 KB Output is correct
17 Correct 3 ms 10576 KB Output is correct
18 Correct 3 ms 10576 KB Output is correct
19 Correct 2 ms 10744 KB Output is correct
20 Correct 2 ms 10576 KB Output is correct
21 Correct 3 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 3 ms 10576 KB Output is correct
24 Correct 3 ms 10576 KB Output is correct
25 Correct 4 ms 10656 KB Output is correct
26 Correct 4 ms 10576 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 3 ms 10756 KB Output is correct
29 Correct 3 ms 10832 KB Output is correct
30 Correct 2 ms 10832 KB Output is correct
31 Correct 5 ms 10832 KB Output is correct
32 Correct 3 ms 10832 KB Output is correct
33 Correct 5 ms 10832 KB Output is correct
34 Correct 3 ms 10832 KB Output is correct
35 Correct 2 ms 10744 KB Output is correct
36 Correct 55 ms 10832 KB Output is correct
37 Correct 139 ms 11088 KB Output is correct
38 Correct 733 ms 11548 KB Output is correct
39 Correct 511 ms 11344 KB Output is correct
40 Correct 70 ms 10832 KB Output is correct
41 Correct 476 ms 11592 KB Output is correct
42 Correct 683 ms 11600 KB Output is correct
43 Correct 29 ms 10832 KB Output is correct
44 Correct 25 ms 10832 KB Output is correct