#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1e18;
struct Comp {
int nod;
ll val;
bool operator <(const Comp &other) const {
return val > other.val;
}
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector < vector < pair <int, int> > > g(N);
for(int i = 0; i < M; i++) {
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
vector <bool> ext(N);
for(int i = 0; i < K; i++) {
ext[P[i]] = 1;
}
priority_queue <Comp> pq;
vector <ll> dst(N);
vector <bool> vis(N);
for(int i = 0; i < N; i++) {
dst[i] = INF;
if(ext[i]) {
continue;
}
vector <int> arr;
for(auto it : g[i]) {
if(ext[it.first]) {
arr.push_back(it.second);
}
}
sort(arr.begin(), arr.end());
if(arr.size() > 1) {
pq.push({i, arr[1]});
dst[i] = arr[1];
}
}
while(pq.size()) {
auto cur = pq.top();
pq.pop();
if(vis[cur.nod]) {
continue;
}
vis[cur.nod] = 1;
for(auto it : g[cur.nod]) {
if(dst[it.first] > cur.val + it.second) {
dst[it.first] = cur.val + it.second;
pq.push({it.first, dst[it.first]});
}
}
}
return dst[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |