#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=1; 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=1; 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]]);
cout << max_element(ans+1, ans+n+1) - ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
508 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |