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;
using ll = long long;
int n, m, k, q;
vector<vector<pair<int, ll>>> gp;
vector<ll> g, mind;
void solve(){
cin >> n >> m;
gp = vector<vector<pair<int, ll>>> (n);
mind = vector<ll> (n, 1e18);
for(int i = 0; i < m; ++i){
int u, v, w; cin >> u >> v >> w;
gp[--u].push_back({--v, w});
gp[v].push_back({u, w});
}
cin >> k;
g = vector<ll> (k);
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for(int i = 0; i < k; ++i) cin >> g[i], --g[i], pq.push({0, g[i]}), mind[g[i]] = 0;
while(pq.size()){
pair<ll, int> p = pq.top();
pq.pop();
ll d = p.first, u = p.second;
if(mind[u] < d) continue;
for(pair<int, ll> v : gp[u]){
if(mind[v.first] > mind[u] + v.second){
mind[v.first] = mind[u] + v.second;
pq.push({mind[v.first], v.first});
}
}
}
cin >> q;
while(q--){
int s, t; cin >> s >> t; --s, --t;
cout << min(mind[s], mind[t]) << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t; while(t--)
solve();
}
# | 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... |