이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[])
{
vector<pair<int,int>> g[n];
for(int i =0;i<m;i++){
g[edges[i][0]].push_back({edges[i][1],w[i]});
g[edges[i][1]].push_back({edges[i][0],w[i]});
}
bool ex[n];
fill(ex,ex+n,0);
for(int i = 0;i<k;i++){
ex[p[i]]=1;
}
bool vis[n];
fill(vis,vis+n,0);
vis[0]=1;
bool rem[n+1];
fill(rem,rem+n+1,0);
priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>>pq; // dist,origin,destination
pq.push({0,n,0});
while(!pq.empty()){
array<int,3> a = pq.top();
pq.pop();
//cout << "popped: " << a[0] << " " << a[1] << " " << a[2] << "\n";
if(ex[a[2]]){
if(rem[a[1]]){
return a[0];
}
else{
rem[a[1]]=1;
continue;
}
}
vis[a[2]]=1;
for(pair<int,int>p:g[a[2]]){
if(vis[p.first])
continue;
//cout << "adding to pq: " << a[0]+p.second << " " << a[2] << " " << p.first << "\n";
pq.push({a[0]+p.second,a[2],p.first});
}
}
assert(0);
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |