Submission #1122934

#TimeUsernameProblemLanguageResultExecution timeMemory
1122934minggaHotspot (NOI17_hotspot)C++17
100 / 100
1140 ms277192 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define int long long const int MOD = 1e9 + 7; const int inf = 2e18; const int N = 5005; int n, m, k, f[N][N], cnt[N][N]; pair<int, int> d[N]; double h[N]; vector<int> g[N]; void bfs(int st) { for(int i = 1; i <= n; i++) f[st][i] = inf; f[st][st] = 0; cnt[st][st] = 1; queue<int> q; q.push(st); while(sz(q)) { int u = q.front(); q.pop(); for(int v : g[u]) { if(f[st][v] > f[st][u] + 1) { f[st][v] = f[st][u] + 1; cnt[st][v] = cnt[st][u]; q.push(v); } else if(f[st][v] == f[st][u] + 1) { cnt[st][v] += cnt[st][u]; } } } } signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> m; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; u++, v++; g[u].pb(v); g[v].pb(u); } cin >> k; for(int i = 1; i <= k; i++) { cin >> d[i].fi >> d[i].se; d[i].fi++, d[i].se++; } for(int i = 1; i <= n; i++) { bfs(i); } int ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { int a = d[j].fi, b = d[j].se; if(f[a][i] + f[i][b] == f[a][b]) { int sus = cnt[a][i] * cnt[i][b]; h[i] += (double) sus / cnt[a][b]; } } if(h[i] > h[ans]) { ans = i; } } cout << ans - 1; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }
#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...