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;
///10:23
const int Nmax = 5005;
long double ans[Nmax];
bool used[Nmax];
vector<int> v[Nmax];
int dist[Nmax][Nmax], pos[Nmax][Nmax], A[Nmax], B[Nmax];
int n, m, k;
void doo(int node, int dist[], int pos[])
{
int i;
for(i=0; i<n; ++i) dist[i] = -1;
dist[node] = 0;
pos[node] = 1;
queue<int> q;
q.push(node);
while(q.size())
{
node = q.front();
q.pop();
for(auto it : v[node])
if(dist[it] == -1)
{
dist[it] = dist[node] + 1;
pos[it] = pos[node];
q.push(it);
}
else if(dist[it] == dist[node] + 1)
pos[it] += pos[node];
}
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
int i, j;
for(i=1; i<=m; ++i)
{
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> k;
for(i=1; i<=k; ++i)
{
cin >> A[i] >> B[i];
if(!used[A[i]]) doo(A[i], dist[A[i]], pos[A[i]]), used[A[i]] = 1;
if(!used[B[i]]) doo(B[i], dist[B[i]], pos[B[i]]), used[B[i]] = 1;
}
for(i=1; i<=k; ++i)
for(j=0; j<n; ++j)
if(dist[A[i]][j] + dist[B[i]][j] == dist[A[i]][B[i]])
ans[j] += (long double) pos[A[i]][j] * pos[B[i]][j] / pos[A[i]][B[i]];
int id = 0;
for(i=0; i<n; ++i)
if(ans[i] > ans[id])
id = i;
cout << id << '\n';
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... |