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 N = 1e5 + 5;
const int inf = 1000000000;
#define F first
#define S second
#define pb push_back
vector<pair<int, int>> g[N];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
int n, m, d[N], p[N], k, qq;
int main() {
cin >> n >> m;
for(int i = 1, a, b, w; i <= m; ++i){
cin >> a >> b >> w;
g[a].pb({b, w});
g[b].pb({a, w});
}
for(int i = 1; i <= n; ++i){
d[i] = inf;
}
cin >> k;
for(int i = 1, x; i <= k; ++i){
cin >> x;
d[x] = 0;
q.push({0, x});
}
while(!q.empty()){
int v = q.top().S;
int d_v = q.top().F;
q.pop();
if(d_v != d[v]) continue;
for(auto edge : g[v]){
int to = edge.F;
int len = edge.S;
if(d[v] + len < d[to]){
d[to] = d[v] + len;
p[to] = v;
q.push({d[to], to});
}
}
}
cin >> qq;
while(qq--){
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... |