Submission #854329

# Submission time Handle Problem Language Result Execution time Memory
854329 2023-09-26T19:39:57 Z annabeth9680 Hotspot (NOI17_hotspot) C++17
100 / 100
586 ms 1612 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5011;
vector<int> adj[MAXN];
long double ans[MAXN];
bool vis[MAXN];
int N;
vector<int> df(MAXN), ds(MAXN), nf(MAXN), ns(MAXN);
void bfs(int src, int dest, vector<int> &nums, vector<int> &dist){
    fill(nums.begin(),nums.end(),0); fill(dist.begin(),dist.end(),1<<30);
    memset(vis,false,sizeof(vis));
    vis[src] = true; dist[src] = 0; nums[src] = 1;
    deque<int> q; q.push_back(src);
    while(!q.empty()){
        int u = q.front(); q.pop_front();
        for(int v : adj[u]){
            if(dist[u]+1 < dist[v]){
                nums[v] = nums[u];
                dist[v] = dist[u]+1;
                if(!vis[v]){
                    q.push_back(v);
                    vis[v] = true;
                }
            }
            else if(dist[u]+1 == dist[v]){
                nums[v] += nums[u];
            }
        }
    }
}
void solve(int src, int dest){
    bfs(src,dest,nf,df); bfs(dest,src,ns,ds);
    int num = nf[dest];
    for(int i = 0;i<N;++i){
        if(df[i]+ds[i] == df[dest]){
            int cur = nf[i]*ns[i];
            ans[i] += (long double) cur/num;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int M; cin >> N >> M;
    for(int i = 0;i<M;++i){
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int Q; cin >> Q;
    for(int i = 0;i<Q;++i){
        int a,b; cin >> a >> b;
        solve(a,b);
    }
    int ret = 0;
    for(int i = 0;i<N;++i){
        if(ans[i] > ans[ret]) ret = i;
    }
    cout << ret << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 660 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 656 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 660 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 656 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 660 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 752 KB Output is correct
16 Correct 1 ms 672 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 856 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 660 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 656 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 660 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 752 KB Output is correct
30 Correct 1 ms 672 KB Output is correct
31 Correct 4 ms 860 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 50 ms 872 KB Output is correct
37 Correct 118 ms 968 KB Output is correct
38 Correct 586 ms 1364 KB Output is correct
39 Correct 367 ms 1372 KB Output is correct
40 Correct 64 ms 1160 KB Output is correct
41 Correct 356 ms 1116 KB Output is correct
42 Correct 479 ms 1612 KB Output is correct
43 Correct 29 ms 860 KB Output is correct
44 Correct 25 ms 600 KB Output is correct