#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
int travel_plan(int n, int m, int edges[][2], int w[], int k, int p[])
{
map<int,int> g[n];
for(int i =0;i<m;i++){
g[edges[i][0]][edges[i][1]]=w[i];
g[edges[i][1]][edges[i][0]]=w[i];
}
bool ex[n];
bool rem[n];
bool vis[n];
fill(rem,rem+n,0);
fill(ex,ex+n,0);
fill(vis,vis+n,0);
priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>>pq; // dist,destination,origin
for(int i = 0;i<k;i++){
vis[p[i]]=1;
ex[p[i]]=1;
for(pair<int,int>pa : g[p[i]]){
pq.push({pa.second,pa.first,p[i]});
}
}
for(int i = 0;i<k;i++){
for(pair<int,int>pa : g[p[i]]){
if(vis[pa.first]) continue;
pq.push({pa.second,pa.first,p[i]});
}
}
while(!pq.empty()){
array<int,3> a = pq.top();
pq.pop();
if(vis[a[1]]){
continue;
}
if(rem[a[1]]){
for(pair<int,int>p:g[a[1]]){
if(vis[p.first]) continue;
pq.push({a[0]+p.second,p.first,a[1]});
}
vis[a[1]]=1;
}
else{
//cout << "removing edge: " << a[1] << " " << a[2] << "\n";
g[a[1]].erase(a[2]);
rem[a[1]]=1;
}
}
fill(vis,vis+n,0);
pq.push({0,0,-1});
vis[0]=1;
while(!pq.empty()){
array<int,3>a=pq.top();
pq.pop();
vis[a[1]]=1;
if(ex[a[1]]) return a[0];
for(pair<int,int>p:g[a[1]]){
if(vis[p.first]) continue;
pq.push({p.second+a[0],p.first,a[1]});
}
}
assert(0);
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |