답안 #1105340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105340 2024-10-26T07:53:31 Z underwaterkillerwhale Hotspot (NOI17_hotspot) C++17
100 / 100
571 ms 1104 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 5e3 + 7;
const int Mod = 1e6 + 3;///lon
const int INF = 1e9 + 7;
const ll BASE = 137;
const int szBL = 550;

int n, m, K;
pii a[N];
vector<int> ke[N];
long double Ans[N];
int D[2][N], dp[2][N];
bool vis[N];

void solution () {
    cin >> n >> m;
    rep (i, 1, m) {
        int u, v;
        cin >> u >> v;
        ++u,++v;
        ke[u].pb(v);
        ke[v].pb(u);
    }
    auto calc = [] (int S, int typ) {
        rep (i, 1, n) {
            D[typ][i] = n + 1;
            dp[typ][i] = vis[i] = 0;
        }
        queue<int> Q;
        Q.push(S);
        D[typ][S] = 0;
        dp[typ][S] = 1;
        while (!Q.empty()) {
            int u = Q.front();
            Q.pop();
            if (vis[u]) continue;
            vis[u] = 1;
            iter (&v, ke[u]) {
                if (D[typ][v] > D[typ][u] + 1) {
                    D[typ][v] = D[typ][u] + 1;
                    dp[typ][v] = dp[typ][u];
                    Q.push(v);
                }
                else if (D[typ][v] == D[typ][u] + 1)  {
                    dp[typ][v] += dp[typ][u];
                }
            }
        }
    };
    cin >> K;
    rep (j, 1, K) {
        cin >> a[j].fs >> a[j].se;
        int S, T;
        tie(S, T) = a[j];
        ++S, ++T;

        calc(S, 0);
        calc(T, 1);

        int delta = D[0][T];
        rep (u, 1, n) {
            if (D[0][u] + D[1][u] == delta) {
                Ans[u] += 1.0 * (dp[0][u] * dp[1][u]) / dp[0][T];
            }
        }
    }
    long double res = 0;
    int opt = 0;
    rep (u, 1, n) {
        if (res < Ans[u]) {
            res = Ans[u];
            opt = u;
        }
    }
    cout << opt - 1 <<"\n";
}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
main () {
//    file("TOY");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
    cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
}
/*
no bug challenge +12

*/

Compilation message

hotspot.cpp:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 1 ms 760 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 4 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 1 ms 760 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 4 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 4 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 48 ms 592 KB Output is correct
37 Correct 112 ms 848 KB Output is correct
38 Correct 571 ms 1084 KB Output is correct
39 Correct 372 ms 848 KB Output is correct
40 Correct 57 ms 848 KB Output is correct
41 Correct 348 ms 1104 KB Output is correct
42 Correct 512 ms 1084 KB Output is correct
43 Correct 23 ms 592 KB Output is correct
44 Correct 19 ms 592 KB Output is correct