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>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 5e3 + 7;
const int Mod = 1e6 + 3;///lon
const int INF = 1e9 + 7;
const ll BASE = 137;
const int szBL = 550;
int n, m, K;
pii a[N];
vector<int> ke[N];
long double Ans[N];
int D[2][N], dp[2][N];
bool vis[N];
void solution () {
cin >> n >> m;
rep (i, 1, m) {
int u, v;
cin >> u >> v;
++u,++v;
ke[u].pb(v);
ke[v].pb(u);
}
auto calc = [] (int S, int typ) {
rep (i, 1, n) {
D[typ][i] = n + 1;
dp[typ][i] = vis[i] = 0;
}
queue<int> Q;
Q.push(S);
D[typ][S] = 0;
dp[typ][S] = 1;
while (!Q.empty()) {
int u = Q.front();
Q.pop();
if (vis[u]) continue;
vis[u] = 1;
iter (&v, ke[u]) {
if (D[typ][v] > D[typ][u] + 1) {
D[typ][v] = D[typ][u] + 1;
dp[typ][v] = dp[typ][u];
Q.push(v);
}
else if (D[typ][v] == D[typ][u] + 1) {
dp[typ][v] += dp[typ][u];
}
}
}
};
cin >> K;
rep (j, 1, K) {
cin >> a[j].fs >> a[j].se;
int S, T;
tie(S, T) = a[j];
++S, ++T;
calc(S, 0);
calc(T, 1);
int delta = D[0][T];
rep (u, 1, n) {
if (D[0][u] + D[1][u] == delta) {
Ans[u] += 1.0 * (dp[0][u] * dp[1][u]) / dp[0][T];
}
}
}
long double res = 0;
int opt = 0;
rep (u, 1, n) {
if (res < Ans[u]) {
res = Ans[u];
opt = u;
}
}
cout << opt - 1 <<"\n";
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
main () {
// file("TOY");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
}
/*
no bug challenge +12
*/
Compilation message (stderr)
hotspot.cpp:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
99 | main () {
| ^~~~
# | 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... |