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;
vector<vector<pair<int, int>>>G;
vector<int>cities;
int main()
{
int n, m, k;
cin >> n >> m >> k;
G.resize(n + 1);
for(int i = 0;i < k;++i){
int a;
cin >> a;
a++;
cities.push_back(a);
}
for(int i = 0;i < m;++i){
int u, v, c;
cin >> u >> v >> c;
u++;
v++;
G[u].push_back({v, c});
}
int q;
cin >> q;
while(q--){
int s, p1, p2, p3, p4, p5;
cin >> s >> p1 >> p2 >> p3 >> p4 >> p5;
s++;
long long mn = 1e18;
priority_queue<pair<long long, int>>pq;
vector<long long>dist(n + 1, 1e18); /// from s to other nodes
vector<bool>check(n + 1);
dist[s] = 0;
pq.push({0, s});
while(!pq.empty()){
int cur = pq.top().second;
pq.pop();
if(check[cur])continue;
check[cur] = 1;
for(pair<long long, int>tempo : G[cur]){
long long v = tempo.first, w = tempo.second;
if(dist[v] > dist[cur] + w){
dist[v] = dist[cur] + w;
pq.push({-dist[v], v});
}
}
}
for(int i : cities){
mn = min(mn, dist[i]);
}
if(mn == 1e18){
cout << -1 << '\n';
}
else cout << mn << '\n';
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |