#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
using ll = long long;
int travel_plan(int n, int M, int R[][2], int L[], int K, int P[]) {
vector<vector<pii>> E(n);
for (int i = 0; i < M; i++) {
E[R[i][0]].push_back({R[i][1], L[i]});
E[R[i][1]].push_back({R[i][0], L[i]});
}
vector<bool> vis(n);
vector<pair<ll, ll>> dis(n, {LLONG_MAX, LLONG_MAX});
priority_queue<pair<ll, int>> q;
for (int i = 0; i < K; i++) {
vis[P[i]] = true;
dis[P[i]] = {0, 0};
q.push({0, P[i]});
}
while (!q.empty()) {
auto [d, x] = q.top(); d = -d; q.pop();
if (d != dis[x].ff) continue;
if (!vis[x]) {
vis[x] = true;
dis[x].ff = dis[x].ss;
dis[x].ss = LLONG_MAX;
if (dis[x].ff != LLONG_MAX) q.push({-dis[x].ff, x});
continue;
}
for (auto [i, w] : E[x]) {
if (d + w < dis[i].ss) {
dis[i].ss = d + w;
if (dis[i].ff > dis[i].ss) swap(dis[i].ff, dis[i].ss);
q.push({-d - w, i});
}
}
}
return dis[0].ff;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |