답안 #537347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537347 2022-03-15T02:55:14 Z ac2hu Hotspot (NOI17_hotspot) C++14
100 / 100
974 ms 1220 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 long 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";
}
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 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 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 508 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 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 2 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 5 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 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 508 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 1 ms 340 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 468 KB Output is correct
24 Correct 5 ms 468 KB Output is correct
25 Correct 7 ms 528 KB Output is correct
26 Correct 8 ms 520 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 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 508 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 2 ms 468 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 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 508 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 1 ms 340 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 468 KB Output is correct
24 Correct 5 ms 468 KB Output is correct
25 Correct 7 ms 528 KB Output is correct
26 Correct 8 ms 520 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 6 ms 596 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 66 ms 596 KB Output is correct
37 Correct 205 ms 812 KB Output is correct
38 Correct 974 ms 1200 KB Output is correct
39 Correct 526 ms 1208 KB Output is correct
40 Correct 121 ms 784 KB Output is correct
41 Correct 632 ms 1212 KB Output is correct
42 Correct 658 ms 1220 KB Output is correct
43 Correct 59 ms 676 KB Output is correct
44 Correct 47 ms 596 KB Output is correct