Submission #1105324

#TimeUsernameProblemLanguageResultExecution timeMemory
1105324tuannmHotspot (NOI17_hotspot)C++17
38 / 100
5 ms764 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 5e3 + 1; const string NAME = "traincentre"; int n, m, k; vector<int> adj[N]; int d[2][N], cnt[2][N]; int q[N]; long double ans[N]; void BFS(int id, int s){ for(int i = 0; i < n; ++i) d[id][i] = N, cnt[id][i] = 0; d[id][s] = 0; cnt[id][s] = 1; int l = 1, r = 1; q[1] = s; while(l <= r){ int u = q[l++]; for(int v : adj[u]){ if(d[id][v] > d[id][u] + 1) d[id][v] = d[id][u] + 1, cnt[id][v] = cnt[id][u], q[++r] = v; else if(d[id][v] == d[id][u]) cnt[id][v] += cnt[id][u]; } } } void inp(){ cin >> n >> m; for(int i = 1; i <= m; ++i){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } void solve(){ cin >> k; while(k--){ int a, b; cin >> a >> b; BFS(0, a); BFS(1, b); for(int w = 0; w < n; ++w) if(d[0][w] + d[1][w] == d[0][b]) ans[w] += (long double) (1LL * cnt[0][w] * cnt[1][w]) / (1.0 * cnt[0][b]); } int res = -1; for(int i = 0; i < n; ++i) if(res == -1 || ans[i] > ans[res]) res = i; cout << res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }

Compilation message (stderr)

hotspot.cpp: In function 'int main()':
hotspot.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen((NAME + ".out").c_str(), "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...