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