# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105366 | LTTrungCHL | Hotspot (NOI17_hotspot) | C++17 | 5 ms | 10832 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.
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
vector <int> lg2;
//void MAKE_LOG_ARR(int n){
// lg2.resize(n + 3);
// for (int i = 1;i <= n;++i){
// lg2[i] = __lg(i);
// }
//}
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, m;
pair <int ,int> disa[N], disb[N];
vector <int> adj[N];
queue <int> q;
pair <long double ,int> e[N];
void solve(){
cin >> n >> m;
for (int i = 0;i < n;++i){
e[i].S = i;
}
for (int i = 1;i <= m;++i){
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
int k;
cin >> k;
for (int ik = 1;ik <= k;++ik){
int a, b;
cin >> a >> b;
for (int i = 0;i < n;++i){
disa[i] = {oo, 0};
disb[i] = {oo, 0};
}
disa[a] = {1,1};
disb[b] = {1,1};
q.push(a);
while (!q.empty()){
int u = q.front();
q.pop();
for (int v : adj[u]){
if (disa[u].F + 1 == disa[v].F){
disa[v].S += disa[u].S;
}
if (disa[u].F + 1 < disa[v].F){
disa[v].F = disa[u].F + 1;
disa[v].S = disa[u].S;
q.push(v);
}
}
}
q.push(b);
while (!q.empty()){
int u = q.front();
q.pop();
for (int v : adj[u]){
if (disb[u].F + 1 == disb[v].F){
disb[v].S += disb[u].S;
}
if (disb[u].F + 1 < disb[v].F){
disb[v].F = disb[u].F + 1;
disb[v].S = disb[u].S;
q.push(v);
}
}
}
for (int i = 0;i < n;++i){
int mia = oo;
int mib = oo;
for (int v : adj[i]){
mia = min(mia, disa[v].F);
mib = min(mib, disb[v].F);
}
if (mia + mib + 1 != disa[b].F) continue;
int suma = 0;
int sumb = 0;
for (int v : adj[i]){
if (disa[v].F == mia){
suma += disa[v].S;
}
if (disb[v].F == mib){
sumb += disb[v].S;
}
}
long double tmp =(suma * sumb);
long double tmp2 = disa[b].S;
e[i].F += tmp/ tmp2;
}
e[a].F += disa[b].S;
e[b].F += disa[b].S;
}
sort(e ,e + n);
cout << e[n - 1].S;
return;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (fopen("ltt.inp", "r")){
freopen("ltt.inp", "r", stdin);
freopen("ltt.out", "w", stdout);
}
// int t;
// cin >> t;
// while(t--){
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... |