Submission #592153

# Submission time Handle Problem Language Result Execution time Memory
592153 2022-07-08T16:49:18 Z angelo_torres Hotspot (NOI17_hotspot) C++17
35 / 100
799 ms 11132 KB
#include <bits/stdc++.h>
#define f(i,j,n) for(int i = j; i < n; ++i)
#define ff first
#define ss second
#define sz(v) (ll) v.size()


using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long double ld;

const int N = 5e3 + 20;
const ll inf = 2e9;
const ll mod = 1e9 + 7;

bool vis[N];
int n,m,k,A[N],B[N];
ll dis[N][N];
vi adj[N];
ll p[N][2];
ld sum[N];
int Ai,Bi;

void bfs(int v){
	f(i,0,n) vis[i] = 0;
	queue<int> q;
	q.push(v);
	p[v][0] = 1;
	while(!q.empty()){
		int cur = q.front();
		q.pop();
		if(vis[cur]) continue;
		vis[cur] = 1;
		for(auto vs : adj[cur]){
			if(dis[Ai][vs] + dis[vs][Bi] != dis[Ai][Bi] or dis[Ai][vs] != dis[Ai][cur]+1) 
				continue;
			p[vs][0] += p[cur][0];
			q.push(vs);
		}
	}
}

void solve(){
	cin >> n >> m;
	f(i,0,n) f(j,0,n) dis[i][j] = 2000000000;
	f(i,0,m){
		int u,v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		dis[u][v] = dis[v][u] = 1;
	}
	cin >> k;
	f(i,0,k) cin >> A[i] >> B[i];
	f(i,0,n) dis[i][i] = 0;
	f(op,0,n){
		f(i,0,n){
			f(j,0,n){
				if(dis[i][j] > dis[i][op] + dis[op][j])
					dis[i][j] = dis[i][op] + dis[op][j];
			}
		}
	}
	f(id,0,k){
		Ai = A[id], Bi = B[id];
		bfs(Ai);
		f(i,0,n) p[i][1] = p[i][0], p[i][0] = 0;
		swap(Ai,Bi);
		bfs(Ai);
		swap(Ai,Bi);
		// f(i,0,n) cout << p[i][0] << " " << p[i][1] << endl;
		f(i,0,n){
			ld pAi = (ld) p[i][1], pBi = (ld) p[i][0];
			sum[i] += (pAi*pBi)/((ld) p[Bi][1]);
		}
	}
	int cy = 0;
	ld ans = sum[0];
	f(i,0,n){
		if(sum[i] > ans) ans = sum[i], cy = i;
	}
	cout << cy << endl;

}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int tc = 1;
	// cin >> tc;
	while(tc--) solve();	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
8 Correct 17 ms 1964 KB Output is correct
9 Correct 145 ms 4868 KB Output is correct
10 Correct 519 ms 9092 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2620 KB Output is correct
14 Correct 208 ms 5844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
8 Incorrect 29 ms 2644 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
8 Correct 17 ms 1964 KB Output is correct
9 Correct 145 ms 4868 KB Output is correct
10 Correct 519 ms 9092 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2620 KB Output is correct
14 Correct 208 ms 5844 KB Output is correct
15 Incorrect 29 ms 2644 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
8 Correct 17 ms 1964 KB Output is correct
9 Correct 145 ms 4868 KB Output is correct
10 Correct 519 ms 9092 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2620 KB Output is correct
14 Correct 208 ms 5844 KB Output is correct
15 Correct 4 ms 1236 KB Output is correct
16 Correct 65 ms 3704 KB Output is correct
17 Correct 345 ms 7460 KB Output is correct
18 Correct 228 ms 6444 KB Output is correct
19 Correct 799 ms 11132 KB Output is correct
20 Correct 11 ms 1748 KB Output is correct
21 Correct 4 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4672 KB Output is correct
2 Correct 444 ms 8804 KB Output is correct
3 Correct 318 ms 7728 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 26 ms 2480 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 118 ms 4780 KB Output is correct
8 Correct 17 ms 1964 KB Output is correct
9 Correct 145 ms 4868 KB Output is correct
10 Correct 519 ms 9092 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2620 KB Output is correct
14 Correct 208 ms 5844 KB Output is correct
15 Incorrect 29 ms 2644 KB Output isn't correct
16 Halted 0 ms 0 KB -