이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
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]});
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... |