답안 #1105323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105323 2024-10-26T07:21:41 Z tuannm Hotspot (NOI17_hotspot) C++17
0 / 100
1 ms 592 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 5e3 + 1;
const string NAME = "traincentre";
int n, m, k;
vector<int> adj[N];
int d[N][2], cnt[N][2];
int q[N];
long double ans[N];

void BFS(int id, int s){
    for(int i = 1; i <= n; ++i)
        d[id][i] = N, cnt[id][i] = 0;

    d[id][s] = 0;
    cnt[id][s] = 1;
    int l = 1, r = 1;
    q[1] = s;

    while(l <= r){
        int u = q[l++];

        for(int v : adj[u]){
            if(d[id][v] > d[id][u] + 1)
                d[id][v] = d[id][u] + 1, cnt[id][v] = cnt[id][u], q[++r] = v;
            else if(d[id][v] == d[id][u])
                cnt[id][v] += cnt[id][u];
        }
    }
}

void inp(){
    cin >> n >> m;
    for(int i = 1; i <= m; ++i){
        int u, v;
        cin >> u >> v;

        adj[u].pb(v);
        adj[v].pb(u);
    }
}

void solve(){
    cin >> k;

    while(k--){
        int a, b;
        cin >> a >> b;

        BFS(0, a);
        BFS(1, b);

        for(int w = 1; w <= n; ++w)
            if(d[0][w] + d[1][w] == d[0][b])
                ans[w] += (long double) ((1LL * cnt[0][w] * cnt[1][w]) / cnt[0][b]);
    }

    int res = 0;
    for(int i = 1; i <= n; ++i)
        if(ans[i] > ans[res])
            res = i;

    cout << res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -