제출 #1131358

#제출 시각아이디문제언어결과실행 시간메모리
1131358vibeduckHotspot (NOI17_hotspot)C++20
38 / 100
148 ms17412 KiB
#include <bits/stdc++.h> 
using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()

typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;

const int mxn = 5e3+5; int n;
pii d[mxn][mxn]; // {min, ways}
vi adj[mxn];

struct b {
    int node, dist, prev;
};

void bfsfunc(int s) {
    queue<b> bfs;
    bfs.push({s, 0, -1}); // {node, dist}
    for (int i = 0; i < n; i++) {
        if (i == s) continue;
        d[s][i] = {0, 0};
    }
    while (bfs.size()) {
        auto cur = bfs.front();
        bfs.pop();
        int rn = d[s][cur.node].fi;
        if (rn) {
            if (cur.dist == rn && cur.prev != -1) {
                d[s][cur.node].se += d[s][cur.prev].se;
            }
            continue;
        }
        d[s][cur.node] = {cur.dist, 1};
        for (auto neighbour : adj[cur.node]) {
            if (neighbour == cur.prev) continue;
            bfs.push({neighbour, cur.dist + 1, cur.node});
        }
    }
}

inline void solve() {
    int m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        adj[a].pb(b); adj[b].pb(a);
    }
    int k; cin >> k; vector<pii> p(k);
    for (int i = 0; i < k; i++) cin >> p[i].fi >> p[i].se;
    for (int i = 0; i < n; i++) bfsfunc(i);

    //for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) cout << i << " " << j << " " << d[i][j].fi << " " << d[i][j].se << "\n";

    vector<ld> ans(n);
    for (int i = 0; i < k; i++) {
        int a = p[i].fi; int b = p[i].se;
        //cout << a << " " << b << " " << d[a][b].se << "\n";
        if (!d[a][b].se) continue;
        for (int w = 0; w < n; w++) {
            if (d[a][w].fi + d[w][b].fi > d[a][b].fi) continue;
            ld cur = (ld)((ld)d[a][w].se * (ld)d[w][b].se) / (ld)(d[a][b].se);     
            ans[w] += cur;
        }
    }
    //for (int i = 0; i < n; i++) cout << setprecision(5) << ans[i] << " ";
    //cout << '\n';
    pii yes = {ans[0], 0}; for (int i = 1; i < n; i++) yes = max(yes, {ans[i], i});
    cout << yes.se << '\n';
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

signed main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    //setIO();

    int t = 1;
    if (tc) {
        cin >> t;
    }

    while (t--) {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

hotspot.cpp: In function 'void setIO(std::string)':
hotspot.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:97:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...