Submission #674919

# Submission time Handle Problem Language Result Execution time Memory
674919 2022-12-26T15:15:39 Z QwertyPi Hotspot (NOI17_hotspot) C++14
100 / 100
737 ms 1284 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5011;
long double Exp[MAXN];
bool vis[MAXN];
vector<int> G[MAXN];
vector<int> du(MAXN), dv(MAXN), cu(MAXN), cv(MAXN); 
void bfs(int u, int v, vector<int>& c, vector<int>& d){
	fill(c.begin(), c.end(), 0);
	fill(d.begin(), d.end(), 1 << 30);
	fill(vis, vis + MAXN, 0);
	deque<int> dq; dq.push_back(u); d[u] = 0; c[u] = 1; vis[u] = true;
	while(dq.size()){
		int t = dq.front(); dq.pop_front();
		for(auto i : G[t]){
			if(d[t] + 1 < d[i]){
				c[i] = c[t];
				d[i] = d[t] + 1;
				if(!vis[i]) dq.push_back(i), vis[i] = true;
			}else if(d[t] + 1 == d[i]){
				c[i] += c[t];
			}
		}
	}
}

bool ok[MAXN];
int n, m;
void solve(int u, int v){
	bfs(u, v, cu, du); bfs(v, u, cv, dv);
	
	int q = cu[v];
	for(int i = 0; i < n; i++){
		int p = cu[i] * cv[i] * (du[i] + dv[i] == du[v]);
		Exp[i] += (long double) p / q;
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[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 ans = 0;
	for(int i = 1; i < n; i++){
		if(Exp[ans] < Exp[i]) ans = i;
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 516 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 2 ms 508 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 5 ms 516 KB Output is correct
27 Correct 2 ms 508 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 516 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 6 ms 652 KB Output is correct
18 Correct 3 ms 520 KB Output is correct
19 Correct 5 ms 592 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 516 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 2 ms 508 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 5 ms 516 KB Output is correct
27 Correct 2 ms 508 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 6 ms 652 KB Output is correct
32 Correct 3 ms 520 KB Output is correct
33 Correct 5 ms 592 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 68 ms 732 KB Output is correct
37 Correct 154 ms 828 KB Output is correct
38 Correct 737 ms 1284 KB Output is correct
39 Correct 523 ms 1236 KB Output is correct
40 Correct 80 ms 724 KB Output is correct
41 Correct 448 ms 1192 KB Output is correct
42 Correct 620 ms 1264 KB Output is correct
43 Correct 38 ms 596 KB Output is correct
44 Correct 32 ms 596 KB Output is correct