# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105325 | tuannm | Hotspot (NOI17_hotspot) | C++17 | 526 ms | 1616 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>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 5e3 + 1;
const string NAME = "traincentre";
int n, m, k;
vector<int> adj[N];
int d[2][N], cnt[2][N];
int q[N];
long double ans[N];
void BFS(int id, int s){
for(int i = 0; i < n; ++i)
d[id][i] = N, cnt[id][i] = 0;
d[id][s] = 0;
cnt[id][s] = 1;
int l = 1, r = 1;
q[1] = s;
while(l <= r){
int u = q[l++];
for(int v : adj[u]){
if(d[id][v] > d[id][u] + 1)
d[id][v] = d[id][u] + 1, cnt[id][v] = cnt[id][u], q[++r] = v;
else if(d[id][v] == d[id][u] + 1)
cnt[id][v] += cnt[id][u];
}
}
}
void inp(){
cin >> n >> m;
for(int i = 1; i <= m; ++i){
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
}
void solve(){
cin >> k;
while(k--){
int a, b;
cin >> a >> b;
BFS(0, a);
BFS(1, b);
for(int w = 0; w < n; ++w)
if(d[0][w] + d[1][w] == d[0][b])
ans[w] += (long double) (1LL * cnt[0][w] * cnt[1][w]) / (1.0 * cnt[0][b]);
}
int res = -1;
for(int i = 0; i < n; ++i)
if(res == -1 || ans[i] > ans[res])
res = i;
cout << res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen((NAME + ".inp").c_str(), "r")){
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
inp();
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... |