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;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector <pair<int,int>> g[1+n];
for (int i = 0; i < m; i++) {
int u, v, cost;
cin >> u >> v >> cost;
g[u].push_back({v, cost});
g[v].push_back({u, cost});
}
int k;
cin >> k;
vector <int> r(k);
for (int i = 0; i < k; i++) {
cin >> r[i];
}
priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> qw;
vector <int> used(1 + n,0);
vector <int> d(1 + n,INT_MAX);
for (int i = 0; i < k; i++) {
qw.push({0, r[i]});
d[r[i]] = 0;
}
while (!qw.empty()) {
int v = qw.top().second;
qw.pop();
if (used[v]) continue;
used[v] = 1;
for (pair<int,int> i : g[v]) {
int to = i.first, len = i.second;
if (d[v] + len < d[to]) {
d[to] = d[v] + len;
qw.push({d[to], to});
}
}
}
int q;
cin >> q;
for (int tmp = q; tmp--;) {
int s, t;
cin >> s >> t;
cout << min(d[s], d[t]) << '\n';
}
return 0;
}
# | 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... |