Submission #765159

#TimeUsernameProblemLanguageResultExecution timeMemory
765159Trisanu_DasHotspot (NOI17_hotspot)C++17
100 / 100
554 ms1128 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=5000, INF=1e9; int n, m, k; double dp[mxN]; ar<int, 2> d1[mxN], d2[mxN]; vector<int> adj[mxN]; void bfs(int s, ar<int, 2>* d) { memset(d, -1, 8*n); d[s]={0, 1}; for (queue<int> q({s}); q.size(); q.pop()) { int u=q.front(); for (int v : adj[u]) { if (d[v][0]==-1) { d[v]={d[u][0]+1, d[u][1]}; q.push(v); } else if (d[u][0]+1==d[v][0]) d[v][1]+=d[u][1]; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i=0; i<m; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } cin >> k; while(k--) { int u, v; cin >> u >> v; bfs(u, d1); bfs(v, d2); double t=d1[v][1]; for (int j=0; j<n; ++j) if (d1[j][0]+d2[j][0]==d1[v][0]) dp[j]+=d1[j][1]*d2[j][1]/t; } cout << max_element(dp, dp+n)-dp; return 0; }
#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...