Submission #1313433

#TimeUsernameProblemLanguageResultExecution timeMemory
1313433levHotspot (NOI17_hotspot)C++20
100 / 100
844 ms155004 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;

#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif

const int mn = 5e3 + 5, mod = 1e9 + 7, inf = 2e9;

int n, m, k, d[mn][mn], cnt[mn][mn], x[mn], y[mn];
vector <int> a[mn];

void bfs(int st, int dist[], int cnt1[]){
	fill(dist, dist + mn, 1e9);
	queue <int> q;
	dist[st] = 0, cnt1[st] = 1;
	q.push(st);

	while(q.size()){
		int u = q.front();
		q.pop();

		for(auto v : a[u]){
			if(dist[v] > dist[u] + 1){
				dist[v] = dist[u] + 1;
				cnt1[v] = cnt1[u];
				q.push(v);
			}
			else if(dist[v] == dist[u] + 1) cnt1[v] += cnt1[u];
		}
	}
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
    	int u, v; cin >> u >> v;
    	u ++, v ++;
    	a[u].push_back(v);
    	a[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) bfs(i, d[i], cnt[i]);
    for(int i = 1; i <= n; i++){
    	for(int j = 1; j <= n; j++){
    		debug(i, j, d[i][j], cnt[i][j]);
    	}
    }
   	cin >> k;
   	int ans = - 1;
   	double mx = - 1.0;
   	for(int i = 0; i < k; i++){
   		cin >> x[i] >> y[i];
   		x[i] ++, y[i] ++;
   	}

   	for(int j = 1; j <= n; j++){
   		double cur = 0;
   		for(int i = 0; i < k; i++){
   			if(d[x[i]][j] + d[j][y[i]] == d[x[i]][y[i]]){
   				cur += (1.0 * cnt[x[i]][j]) * (1.0 * cnt[j][y[i]]) / (1.0 * cnt[x[i]][y[i]]);
   			}
   		}
   		debug(cur, j);
   		if(cur > mx){
   			mx = cur;
   			ans = j;
   		}
   	}

   	cout << ans - 1 << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #define task "Kawabata"
    if (fopen(task".INP", "r")) {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro

Compilation message (stderr)

hotspot.cpp: In function 'int main()':
hotspot.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...