# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105362 | nghia0912 | Hotspot (NOI17_hotspot) | C++17 | 4 ms | 760 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.
#define COPYRIGHT CODE BY TRINH TUAN NGHIA
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("popcnt")
#define Boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define endl "\n"
#define st first
#define nd second
#define ii pair <int,int>
#define iii pair <int,ii>
#define iiii pair <ii,ii>
#define pb push_back
#define NAME "traincentre"
using namespace std;
const int N = 5e3 + 10;
const int M = 4e4 + 10;
int n, m, k;
vector<int> adj[N];
long double E[N];
ll d[N], d2[N];
ll f[N], f2[N];
vector<ii> cb;
void BFS(int st, int en){
queue<int> q;
for (int i = 0; i < n;++i){
d[i] = 3e18;
d2[i] = 3e18;
f[i] = 0;
f2[i] = 0;
}
f[st] = 1;
d[st] = 0;
d2[en] = 0;
f2[en] = 1;
q.push(st);
while (!q.empty()){
int u = q.front();q.pop();
for (auto v : adj[u]){
if (d[u] + 1 < d[v]){
d[v] = d[u] + 1;
f[v] = f[u];
q.push(v);
}
else if (d[u] + 1 == d[v]){
f[v] += f[u];
}
}
}
q.push(en);
while (!q.empty()){
int u = q.front();q.pop();
for (auto v : adj[u]){
if (d2[u] + 1 < d2[v]){
d2[v] = d2[u] + 1;
f2[v] = f2[u];
q.push(v);
}
else if (d2[u] + 1 == d2[v]){
f2[v] += f2[u];
}
}
}
for (int i = 0; i < n; ++i){
if (d[i] + d2[i] != d[en])continue;
long double cc = f[i] * f2[i];
E[i] = cc / f[en];
// cout << i << " " << cc << " " << f[en] << endl;
}
}
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);
}
cin >> k;
for (int i =1; i <= k; ++i){
int x, y;
cin>> x >> y;
cb.pb({x, y});
}
}
void solve(){
for (auto x : cb){
BFS(x.st, x.nd);
}
int mx = -1;
for (int i= 0; i < n; ++i){
if (mx == -1 or E[i] > E[mx]){
mx = i;
}
// cout << i << " " << E[i] << endl;
}
cout <<mx << endl;
}
signed main (){
if (fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
Boost;
inp();
solve();
}
/*
input
*/
/*
output
*/
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... |