# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1131364 | vibeduck | Hotspot (NOI17_hotspot) | C++20 | 150 ms | 17480 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
const int mxn = 5e3+5; int n;
pii d[mxn][mxn]; // {min, ways}
vi adj[mxn];
struct b {
int node, dist, prev;
};
void bfsfunc(int s) {
queue<b> bfs;
bfs.push({s, 0, -1}); // {node, dist}
for (int i = 0; i < n; i++) {
//if (i == s) continue;
d[s][i] = {1e18, 0};
}
while (bfs.size()) {
auto cur = bfs.front();
bfs.pop();
int rn = d[s][cur.node].fi;
if (rn != 1e18) {
if (cur.dist == rn && cur.prev != -1) {
d[s][cur.node].se += d[s][cur.prev].se;
}
continue;
}
d[s][cur.node] = {cur.dist, 1};
for (auto neighbour : adj[cur.node]) {
if (neighbour == cur.prev) continue;
bfs.push({neighbour, cur.dist + 1, cur.node});
}
}
}
inline void solve() {
int m; cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
adj[a].pb(b); adj[b].pb(a);
}
int k; cin >> k; vector<pii> p(k);
for (int i = 0; i < k; i++) cin >> p[i].fi >> p[i].se;
for (int i = 0; i < n; i++) bfsfunc(i);
//for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) cout << i << " " << j << " " << d[i][j].fi << " " << d[i][j].se << "\n";
vector<ld> ans(n);
for (int i = 0; i < k; i++) {
int a = p[i].fi; int b = p[i].se;
//cout << a << " " << b << " " << d[a][b].se << "\n";
if (d[a][b].fi == 1e18) continue;
for (int w = 0; w < n; w++) {
if (d[a][w].fi == 1e18 || d[w][b].fi == 1e18) continue;
if (d[a][w].fi + d[w][b].fi > d[a][b].fi) continue;
ld cur = (ld)((ld)d[a][w].se * (ld)d[w][b].se) / (ld)(d[a][b].se);
ans[w] += cur;
}
}
//for (int i = 0; i < n; i++) cout << setprecision(5) << ans[i] << " ";
//cout << '\n';
pii yes = {ans[0], 0}; for (int i = 1; i < n; i++) yes = max(yes, {ans[i], i});
cout << yes.se << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}
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... |