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;
const int MAXN = 5011;
long double Exp[MAXN];
bool vis[MAXN];
vector<int> G[MAXN];
vector<int> du(MAXN), dv(MAXN), cu(MAXN), cv(MAXN);
void bfs(int u, int v, vector<int>& c, vector<int>& d){
fill(c.begin(), c.end(), 0);
fill(d.begin(), d.end(), 1 << 30);
fill(vis, vis + MAXN, 0);
deque<int> dq; dq.push_back(u); d[u] = 0; c[u] = 1; vis[u] = true;
while(dq.size()){
int t = dq.front(); dq.pop_front();
for(auto i : G[t]){
if(d[t] + 1 < d[i]){
c[i] = c[t];
d[i] = d[t] + 1;
if(!vis[i]) dq.push_back(i), vis[i] = true;
}else if(d[t] + 1 == d[i]){
c[i] += c[t];
}
}
}
}
bool ok[MAXN];
int n, m;
void solve(int u, int v){
bfs(u, v, cu, du); bfs(v, u, cv, dv);
int q = cu[v];
for(int i = 0; i < n; i++){
int p = cu[i] * cv[i] * (du[i] + dv[i] == du[v]);
Exp[i] += (long double) p / q;
}
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
int q; cin >> q;
for(int i = 0; i < q; i++){
int a, b; cin >> a >> b;
solve(a, b);
}
int ans = 0;
for(int i = 1; i < n; i++){
if(Exp[ans] < Exp[i]) ans = i;
}
cout << ans << endl;
}
# | 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... |