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;
const int INF = 1000000000;
int main(){
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> E(n);
for (int i = 0; i < m; i++){
int a, b, w;
cin >> a >> b >> w;
a--;
b--;
E[a].push_back(make_pair(w, b));
E[b].push_back(make_pair(w, a));
}
int k;
cin >> k;
vector<int> g(k);
for (int i = 0; i < k; i++){
cin >> g[i];
g[i]--;
}
vector<int> d(n, -1);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int i = 0; i < k; i++){
pq.push(make_pair(0, g[i]));
}
while (!pq.empty()){
int c = pq.top().first;
int v = pq.top().second;
pq.pop();
if (d[v] == -1){
d[v] = c;
for (auto P : E[v]){
int w = P.second;
if (d[w] == -1){
pq.push(make_pair(c + P.first, w));
}
}
}
}
int Q;
cin >> Q;
int s, t;
cin >> s >> t;
s--;
t--;
int tv = 0, fv = INF;
while (fv - tv > 1){
int mid = (tv + fv) / 2;
if (d[s] < mid){
fv = mid;
} else {
vector<bool> used(n, false);
used[s] = true;
queue<int> q;
q.push(s);
while (!q.empty()){
int v = q.front();
q.pop();
for (auto P : E[v]){
int w = P.second;
if (d[w] >= mid && !used[w]){
used[w] = true;
q.push(w);
}
}
}
if (used[t]){
tv = mid;
} else {
fv = mid;
}
}
}
cout << tv << endl;
}
# | 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... |