Submission #537348

# Submission time Handle Problem Language Result Execution time Memory
537348 2022-03-15T02:56:18 Z ac2hu Hotspot (NOI17_hotspot) C++14
100 / 100
1014 ms 980 KB
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else 
#define deb(x...)
#endif
using namespace std;
#define ll long long 
#define ld double 
const int N = 5001;
int n,m,k;
vector<int> adj[N];
int d1[N], d2[N] ,p1[N], p2[N];
ld e[N];
signed main() {
	iostream::sync_with_stdio(false);
	cin.tie(nullptr);cout.tie(nullptr);
	cout << setprecision(10);
	cin >> n >> m;
	for(int _ = 0;_<m;_++){
		int a,b;cin >> a >> b;
		// a--;b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	cin >> k;
	for(int _ = 0;_<k;_++){
		int s,t;cin >> s >> t;
		for(int i = 0;i<n;i++){
			d1[i] = 1e9;
			d2[i] = 1e9;
			p1[i] = 0;
			p2[i] = 0;
		}
		list<int> q;
		d1[s] = 0;
		p1[s] = 1;
		q.push_back(s);
		while(!q.empty()){
			int x = q.front();
			q.pop_front();
			// cout << x << "--> : ";
			for(int e : adj[x]){
				if(d1[e] > d1[x]){
					p1[e] += p1[x];
				}
				if(d1[e] > d1[x] + 1){
					d1[e] = d1[x] + 1;
					// cout << e << " ";
					q.push_back(e);
				}
			}
			// cout << "\n";
		}
		// cout << "\n";
		// p2 shortest paths to t
		d2[t] = 0;
		p2[t] = 1;
		q.push_back(t);
		while(!q.empty()){
			int x = q.front();
			q.pop_front();
			for(int e : adj[x]){
				if(d2[e] > d2[x])
					p2[e] += p2[x];
				if(d2[e] > d2[x] + 1){
					d2[e] = d2[x] + 1;
					q.push_back(e);
				}
			}
		}
      	assert(p1[t] == p2[s]);
		ll total = p1[t];
		// assert(p1[t] == p2[s]);
		for(int i = 0;i<n;i++){
			ll paths = p1[i]*p2[i];
			if(d1[i] + d2[i] == d1[t] && d1[t] < 1e8)
				e[i] += ((ld)paths/total);
		}
		// cout << s << " " << t << "\n";
		// cout << "distance from " << s << " to i: \n";
		// for(int i = 0;i<n;i++)
		// 	cout << d1[i] << " ";
		// cout << "\n";
		// cout << "distance from " << t << " to i: \n";
		// for(int i = 0;i<n;i++)
		// 	cout << d2[i] << " ";
		// cout << "\n";
		// cout << "paths from " << s << " to i: \n";
		// for(int i = 0;i<n;i++)
		// 	cout << p1[i] << " ";
		// cout << "\n";
		// cout << "paths from " << t << " to i: \n";
		// for(int i = 0;i<n;i++)
		// 	cout << p2[i] << " ";
		// cout << "\n";
		// cout << "------------\n";
	}
	// for(int i = 0;i<n;i++)
	// 	cout << e[i] << " ";
	// cout << "\n";
	cout << max_element(e, e + n) - e << "\n";
}
# 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 0 ms 340 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 0 ms 340 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 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 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 0 ms 340 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 3 ms 468 KB Output is correct
10 Correct 3 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 340 KB Output is correct
14 Correct 5 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 0 ms 340 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 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 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 340 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 416 KB Output is correct
24 Correct 5 ms 468 KB Output is correct
25 Correct 7 ms 520 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 6 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 0 ms 340 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 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 3 ms 540 KB Output is correct
21 Correct 2 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 0 ms 340 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 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 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 340 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 416 KB Output is correct
24 Correct 5 ms 468 KB Output is correct
25 Correct 7 ms 520 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 5 ms 468 KB Output is correct
34 Correct 3 ms 540 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 66 ms 596 KB Output is correct
37 Correct 186 ms 696 KB Output is correct
38 Correct 1014 ms 980 KB Output is correct
39 Correct 539 ms 884 KB Output is correct
40 Correct 127 ms 680 KB Output is correct
41 Correct 640 ms 952 KB Output is correct
42 Correct 753 ms 916 KB Output is correct
43 Correct 54 ms 616 KB Output is correct
44 Correct 48 ms 604 KB Output is correct