Submission #1106744

# Submission time Handle Problem Language Result Execution time Memory
1106744 2024-10-31T02:33:46 Z fryingduc Hotspot (NOI17_hotspot) C++17
100 / 100
571 ms 1360 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif

const int maxn = 5005;
int n, m, k;
vector<int> g[maxn];

int d[maxn], rev_d[maxn];
long long cnt[maxn], rev_cnt[maxn];

long double f[maxn];
  
void bfs(int src, int d[], long long cnt[]) {
  for(int i = 1; i <= n; ++i) {
    d[i] = 1e9;
    cnt[i] = 0;
  }
  queue<int> q;
  q.push(src);
  d[src] = 0, cnt[src] = 1;
  while(!q.empty()) {
    int u = q.front();
    q.pop();
    for(auto v:g[u]) {
      if(d[v] > d[u] + 1) {
        d[v] = d[u] + 1;
        cnt[v] = cnt[u];
        q.push(v);
      }
      else if(d[v] == d[u] + 1) {
        cnt[v] += cnt[u];
      }
    }
  }  
}
void solve() {
  cin >> n >> m;
  for(int i = 1; i <= m; ++i) {
    int u, v; cin >> u >> v;
    ++u, ++v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int q; cin >> q;
  while(q--) {
    int u, v; cin >> u >> v;
    ++u, ++v;
    bfs(u, d, cnt);
    bfs(v, rev_d, rev_cnt);
    
    for(int i = 1; i <= n; ++i) {
      if(d[i] + rev_d[i] == d[v]) {
        f[i] += (1.0 * cnt[i] * rev_cnt[i]) / cnt[v];
      }
    }
  }
  
  int res = 0;
  for(int i = 1; i <= n; ++i) {
    if(res == 0 || f[res] < f[i]) res = i;
  }
  cout << res - 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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 764 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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 2 ms 592 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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 764 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 2 ms 592 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 2 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 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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 764 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 760 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 580 KB Output is correct
19 Correct 3 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 588 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 764 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 2 ms 592 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 2 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 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 760 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 580 KB Output is correct
33 Correct 3 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 105 ms 848 KB Output is correct
38 Correct 571 ms 1104 KB Output is correct
39 Correct 340 ms 1104 KB Output is correct
40 Correct 57 ms 848 KB Output is correct
41 Correct 341 ms 1104 KB Output is correct
42 Correct 484 ms 1360 KB Output is correct
43 Correct 23 ms 592 KB Output is correct
44 Correct 19 ms 848 KB Output is correct