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;
#define ll long long
const ll inf = 100000000000000;
struct edge {
int v;
int weight;
};
int main() {
int N, E, K;
cin >> N >> E >> K;
vector<int> T;
for (int i = 0; i < K; i++) {
int Ki;
cin >> Ki;
T.push_back(Ki);
}
vector<vector<edge>> AL (N);
for (int i = 0; i < E; i++) {
int U, V, C;
cin >> U >> V >> C;
AL[V].push_back({U,C});
}
map<int,ll> dist;
map<int,bool> done;
for (int i = 0; i < N; i++) {
dist[i] = inf;
done[i] = false;
}
using pli = pair<ll,int>;
priority_queue<pli,vector<pli>,greater<pli>> pq;
for (auto p = T.begin(); p != T.end(); p++) {
pq.push({0,*p});
dist[*p] = 0;
}
while (!pq.empty()) {
auto [_,u] = pq.top();
pq.pop();
if (!done[u]) {
for (edge& e: AL[u]) {
if (dist[e.v] > dist[u] + e.weight) {
dist[e.v] = dist[u] + e.weight;
pq.push({dist[e.v],e.v});
}
}
done[u] = true;
}
}
/*
for (int i = 0; i < N; i++) {
cout << dist[i] << ' ';
}
cout << endl;*/
int Q;
cin >> Q;
for (int i = 0; i < Q; i++) {
vector<int> P;
int S;
cin >> S;
for (int i = 0; i < 5; i++) {
int Pi;
cin >> Pi;
P.push_back(Pi);
}
if (dist[S] == inf) {
cout << -1 << endl;
} else {
cout << dist[S] << endl;
}
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | auto [_,u] = pq.top();
| ^
# | 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... |