답안 #1105384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105384 2024-10-26T08:58:16 Z monaxia Hotspot (NOI17_hotspot) C++17
100 / 100
1513 ms 245832 KB
// credit: Mai Hong Kien
 
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define mod (long long)(1e9 + 7)
#define eps (long long)(1e-9)
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll LIMIT = 2e3 + 5;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random (ll l, ll r){return uniform_int_distribution <ll> (l, r)(rng);}
 
 
void solve(){
    ll n, m;
    long double mx = 0, res = 0;
    cin >> n >> m;
 
    vector <vector <ll>> graph(n + 1), dist(n + 1, vector <ll> (n + 1, INT_MAX)), path(n + 1, vector <ll> (n + 1, 0));
    vector <long double> e(n + 1, 0);
    vector <pair <ll, ll>> range;
 
    for(ll i = 1; i <= m; i ++){
        ll u, v;
        cin >> u >> v;
 
        graph[u].pb(v);
        graph[v].pb(u);
    }
 
    for(ll i = 0; i < n; i ++){
        dist[i][i] = 0;
        path[i][i] = 1;
 
        vector <ll> v(n + 1, 0);
        queue <ll> q;
 
        q.push(i);
 
        while(!q.empty()){
            ll s = q.front();
            for(auto& x : graph[s]){
                if(dist[i][x] > dist[i][s] + 1) {
                    dist[i][x] = dist[i][s] + 1;
                    path[i][x] = path[i][s];

                    v[x] = 1;
                    q.push(x);
                } 
 
                else if(dist[i][x] == dist[i][s] + 1) path[i][x] += path[i][s];

                v[x] = 1;
            }
 
            q.pop();
        }
    }
 
    ll k;
    cin >> k;
 
    for(ll i = 1; i <= k; i ++){
        ll u, v;
        cin >> u >> v;
 
        range.pb({u, v});
    }
 
    for(ll i = 0; i < n; i ++){
        for(auto& x : range){
            if(dist[i][x.fr] + dist[i][x.sc] > dist[x.fr][x.sc]) continue;
            else if(path[x.fr][x.sc] != 0) e[i] += ld(path[i][x.fr] * path[i][x.sc]) / ld(path[x.fr][x.sc]);
            // cout << x.fr << " " << x.sc << " " << ld(dist[i][x.fr] * dist[i][x.sc]) / ld(dist[x.fr][x.sc]) << "\n";
        }
 
        if(e[i] > mx) mx = e[i], res = i;
        // cout << e[i] << " ";
        // cout << "\n";
    }
 
    cout << res;
}
 
 
signed main()
{
    // cin.tie(0)->sync_with_stdio(0);
 
    if(fopen("TOY.inp", "r")){
        freopen("TOY.inp", "r", stdin);
        freopen("TOY.out", "w", stdout);
    }
    
    // cout << 1; return 0;
 
    ll n = 1;
 
    // cin >> n;
 
    while(n) {
        solve();
        n --;
        cout << "\n";
    }
 
    // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen("TOY.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen("TOY.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 2 ms 1360 KB Output is correct
9 Correct 9 ms 4944 KB Output is correct
10 Correct 23 ms 11088 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 3 ms 2296 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 4 ms 2296 KB Output is correct
9 Correct 10 ms 6480 KB Output is correct
10 Correct 7 ms 5200 KB Output is correct
11 Correct 17 ms 11344 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 4 ms 2128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 2 ms 1360 KB Output is correct
9 Correct 9 ms 4944 KB Output is correct
10 Correct 23 ms 11088 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 3 ms 2296 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
15 Correct 4 ms 2296 KB Output is correct
16 Correct 10 ms 6480 KB Output is correct
17 Correct 7 ms 5200 KB Output is correct
18 Correct 17 ms 11344 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 4 ms 2128 KB Output is correct
22 Correct 5 ms 3152 KB Output is correct
23 Correct 4 ms 2384 KB Output is correct
24 Correct 13 ms 6736 KB Output is correct
25 Correct 28 ms 13832 KB Output is correct
26 Correct 22 ms 11856 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 6 ms 3324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 2 ms 1360 KB Output is correct
9 Correct 9 ms 4944 KB Output is correct
10 Correct 23 ms 11088 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 3 ms 2296 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
15 Correct 11 ms 848 KB Output is correct
16 Correct 15 ms 3408 KB Output is correct
17 Correct 50 ms 8528 KB Output is correct
18 Correct 27 ms 7248 KB Output is correct
19 Correct 63 ms 14416 KB Output is correct
20 Correct 9 ms 1360 KB Output is correct
21 Correct 3 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4688 KB Output is correct
2 Correct 16 ms 10680 KB Output is correct
3 Correct 15 ms 9040 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 1872 KB Output is correct
6 Correct 2 ms 1360 KB Output is correct
7 Correct 7 ms 4688 KB Output is correct
8 Correct 2 ms 1360 KB Output is correct
9 Correct 9 ms 4944 KB Output is correct
10 Correct 23 ms 11088 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 3 ms 2296 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
15 Correct 4 ms 2296 KB Output is correct
16 Correct 10 ms 6480 KB Output is correct
17 Correct 7 ms 5200 KB Output is correct
18 Correct 17 ms 11344 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 4 ms 2128 KB Output is correct
22 Correct 5 ms 3152 KB Output is correct
23 Correct 4 ms 2384 KB Output is correct
24 Correct 13 ms 6736 KB Output is correct
25 Correct 28 ms 13832 KB Output is correct
26 Correct 22 ms 11856 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 6 ms 3324 KB Output is correct
29 Correct 11 ms 848 KB Output is correct
30 Correct 15 ms 3408 KB Output is correct
31 Correct 50 ms 8528 KB Output is correct
32 Correct 27 ms 7248 KB Output is correct
33 Correct 63 ms 14416 KB Output is correct
34 Correct 9 ms 1360 KB Output is correct
35 Correct 3 ms 848 KB Output is correct
36 Correct 25 ms 1556 KB Output is correct
37 Correct 137 ms 22052 KB Output is correct
38 Correct 1231 ms 187696 KB Output is correct
39 Correct 122 ms 9800 KB Output is correct
40 Correct 498 ms 143700 KB Output is correct
41 Correct 1513 ms 245832 KB Output is correct
42 Correct 313 ms 25160 KB Output is correct
43 Correct 197 ms 63560 KB Output is correct
44 Correct 197 ms 63560 KB Output is correct