#include "bits/stdc++.h"
#include "crocodile.h"
#define i64 long long
using namespace std;
const i64 inf = 1e18 + 18;
const i64 sz = 1e5 + 5;
vector<vector<i64>> aj[sz];
bool vi[sz];
i64 d[sz][2];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i = 0; i < M; i ++) {
i64 le = R[i][0];
i64 ri = R[i][1];
aj[le].push_back({ri, L[i]});
aj[ri].push_back({le, L[i]});
}
for (i64 i = 0; i < N; i ++) {
d[i][0] = inf;
d[i][1] = inf;
}
priority_queue<vector<i64>> pq;
for (i64 i = 0; i < K; i ++) {
pq.push({0, P[i]});
d[P[i]][0] = 0;
d[P[i]][1] = 0;
}
while (!pq.empty()) {
auto vc = pq.top();
pq.pop();
i64 v = vc[1];
i64 ev = -vc[0];
if (vi[v]) {
continue;
}
vi[v] = true;
for (auto& uc : aj[v]) {
i64 u = uc[0];
i64 eu = uc[1];
if (vi[u]) {
break;
}
if (ev + eu < d[u][0]) {
d[u][1] = d[u][0];
d[u][0] = ev + eu;
} else {
d[u][1] = min(d[u][1], ev + eu);
}
pq.push({-d[u][1], u});
}
}
return d[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |