This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |