This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Author : Vu Khac Minh
* Created : 08.03.2024
**/
#include <bits/stdc++.h>
#define MASK(x) ((1ll) << (x))
#define BIT(x, i) (((x) >> (i)) & (1))
#define c_bit(i) __builtin_popcountll(i)
#define SET_ON(x, i) ((x) | MASK(i))
#define SET_OFF(x, i) ((x) & ~MASK(i))
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define db(val) "["#val" = " << (val) << "] "
#define ll long long
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9+7;
void file()
{
#define Task "ROUNDPRI"
if(fopen(Task".inp","r"))
{
freopen(Task".inp","r",stdin);
freopen(Task".out","w",stdout);
}
}
int n, m, k;
vector<int> adj[maxn];
ll dista[maxn], distb[maxn], cnta[maxn], cntb[maxn];
long double res[maxn];
void bfs(int s, ll dist[], ll cnt[])
{
FOR(u, 0, n - 1)
{
dist[u] = 1e18;
cnt[u] = 0;
}
dist[s] = 0;
cnt[s] = 1;
queue<int> q;
q.push(s);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : adj[u]) {
if (dist[u] + 1 < dist[v]) {
dist[v] = dist[u] + 1;
cnt[v] = cnt[u];
q.push(v);
} else if (dist[u] + 1 == dist[v]) {
cnt[v] += cnt[u];
}
}
}
}
void solve()
{
cin >> n >> m;
FOR(i, 1, m)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin >> k;
FOR(i, 1, k)
{
int a, b;
cin >> a >> b;
bfs(a, dista, cnta);
bfs(b, distb, cntb);
FOR(u, 0, n - 1)
{
if (dista[u] + distb[u] == dista[b])
{
long double c = cnta[u] * cntb[u];
res[u] += c / cnta[b];
}
}
}
long double best = 0;
int pos = 0;
FOR(i, 0, n - 1)
{
if (res[i] > best)
{
best = res[i];
pos = i;
}
}
cout << pos << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
file();
//cin >> ntest;
while (ntest--)
{
solve();
}
return 0;
}
Compilation message (stderr)
hotspot.cpp: In function 'void file()':
hotspot.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen(Task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(Task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |