# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102915 | Avocabo | Hotspot (NOI17_hotspot) | C++17 | 2 ms | 6480 KiB |
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;
#define task ""
#define fi first
#define se second
#define pii pair <int, int>
#define pb push_back
#define ll long long
#define pip pair <int, pii>
#define pli pair <ll, int>
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
int myabs(int x)
{
return x < 0 ? -x : x;
}
int n, m, k;
vector <int> g[N];
long long cnt[2][N], d[2][N];
double ans[N];
void inp()
{
cin >> n >> m;
for (int i=1; i<=m; ++i)
{
int u, v;
cin >> u >> v;
u++;
v++;
g[u].push_back(v);
g[v].push_back(u);
}
cin >> k;
}
void bfs(int id, int s)
{
queue <int> q;
for (int i=0; i<=n; ++i)
d[id][i] = inf,
cnt[id][i] = 0;
d[id][s] = 0;
q.push(s);
cnt[id][s] = 1;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int v : g[u])
{
if (d[id][v] > d[id][u] + 1)
{
d[id][v] = d[id][u] + 1;
cnt[id][v] = cnt[id][u];
q.push(v);
}
else if (d[id][v] == d[id][u] + 1)
cnt[id][v] += cnt[id][u];
}
}
}
void solve()
{
while (k--)
{
int a, b;
cin >> a >> b;
a++;
b++;
bfs(0, a);
bfs(1, b);
double tmp = cnt[0][b];
for (int i=1; i<=n; ++i)
if (d[0][i] + d[1][i] == d[0][b])
{
double tmp1 = (double)(cnt[0][i] * cnt[1][i]);
ans[i] += (tmp1/tmp);
}
}
int res = 0;
for (int i=1; i<=n; ++i)
if (ans[i] > ans[res])
res = i;
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
inp();
solve();
return 0;
}
Compilation message (stderr)
# | 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... |