#include<bits/stdc++.h>
using namespace std;
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
const int N = 1e5 + 5;
vector<pii> adj[N];
int cnt[N];
void connect(int u, int v, int w) {
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
int travel_plan(int n, int nEdges, int R[][2], int l[], int nExits, int a[]) {
priority_queue<pii, vector<pii>, greater<pii>> Q;
for(int i = 0; i < nEdges; i++)
connect(R[i][0], R[i][1], l[i]);
for(int i = 0; i < nExits; i++) {
cnt[a[i]]++;
Q.emplace(0, a[i]);
}
for(int i = 0; i < n; i++)
sort(ALL(adj[i]), [&](pii a, pii b) {
return a.second < b.second;
});
int ans = -1;
while(!Q.empty()) {
auto [weight, u] = Q.top();
Q.pop();
cnt[u]++;
if(cnt[u] == 2) {
for(auto [v, w] : adj[u]) {
if(v == 0) {
ans = weight + w;
break;
}
Q.emplace(weight + w, v);
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |