Submission #592149

# Submission time Handle Problem Language Result Execution time Memory
592149 2022-07-08T16:41:55 Z angelo_torres Hotspot (NOI17_hotspot) C++17
35 / 100
721 ms 7708 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],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] = n+5;
	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 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
8 Correct 13 ms 1728 KB Output is correct
9 Correct 150 ms 3740 KB Output is correct
10 Correct 497 ms 6412 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2208 KB Output is correct
14 Correct 182 ms 4388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
8 Incorrect 46 ms 2260 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
8 Correct 13 ms 1728 KB Output is correct
9 Correct 150 ms 3740 KB Output is correct
10 Correct 497 ms 6412 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2208 KB Output is correct
14 Correct 182 ms 4388 KB Output is correct
15 Incorrect 46 ms 2260 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
8 Correct 13 ms 1728 KB Output is correct
9 Correct 150 ms 3740 KB Output is correct
10 Correct 497 ms 6412 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2208 KB Output is correct
14 Correct 182 ms 4388 KB Output is correct
15 Correct 4 ms 1236 KB Output is correct
16 Correct 80 ms 2952 KB Output is correct
17 Correct 336 ms 5432 KB Output is correct
18 Correct 269 ms 4776 KB Output is correct
19 Correct 721 ms 7708 KB Output is correct
20 Correct 19 ms 1620 KB Output is correct
21 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3612 KB Output is correct
2 Correct 444 ms 6252 KB Output is correct
3 Correct 318 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 31 ms 2100 KB Output is correct
6 Correct 12 ms 1672 KB Output is correct
7 Correct 115 ms 3684 KB Output is correct
8 Correct 13 ms 1728 KB Output is correct
9 Correct 150 ms 3740 KB Output is correct
10 Correct 497 ms 6412 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2208 KB Output is correct
14 Correct 182 ms 4388 KB Output is correct
15 Incorrect 46 ms 2260 KB Output isn't correct
16 Halted 0 ms 0 KB -