Submission #592145

# Submission time Handle Problem Language Result Execution time Memory
592145 2022-07-08T16:34:46 Z angelo_torres Hotspot (NOI17_hotspot) C++17
35 / 100
610 ms 7768 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];
double 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){
			double pAi = (double) p[i][1], pBi = (double) p[i][0];
			sum[i] += (pAi*pBi)/((double) p[Bi][1]);
		}
	}
	int cy = 0;
	double 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 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
8 Correct 13 ms 1724 KB Output is correct
9 Correct 130 ms 3744 KB Output is correct
10 Correct 410 ms 6424 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2212 KB Output is correct
14 Correct 173 ms 4384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
8 Incorrect 32 ms 2260 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
8 Correct 13 ms 1724 KB Output is correct
9 Correct 130 ms 3744 KB Output is correct
10 Correct 410 ms 6424 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2212 KB Output is correct
14 Correct 173 ms 4384 KB Output is correct
15 Incorrect 32 ms 2260 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
8 Correct 13 ms 1724 KB Output is correct
9 Correct 130 ms 3744 KB Output is correct
10 Correct 410 ms 6424 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2212 KB Output is correct
14 Correct 173 ms 4384 KB Output is correct
15 Correct 4 ms 1236 KB Output is correct
16 Correct 72 ms 2984 KB Output is correct
17 Correct 310 ms 5484 KB Output is correct
18 Correct 224 ms 4776 KB Output is correct
19 Correct 610 ms 7768 KB Output is correct
20 Correct 11 ms 1620 KB Output is correct
21 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3632 KB Output is correct
2 Correct 391 ms 6248 KB Output is correct
3 Correct 307 ms 5588 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 23 ms 2088 KB Output is correct
6 Correct 12 ms 1620 KB Output is correct
7 Correct 134 ms 3692 KB Output is correct
8 Correct 13 ms 1724 KB Output is correct
9 Correct 130 ms 3744 KB Output is correct
10 Correct 410 ms 6424 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 27 ms 2212 KB Output is correct
14 Correct 173 ms 4384 KB Output is correct
15 Incorrect 32 ms 2260 KB Output isn't correct
16 Halted 0 ms 0 KB -