#include "bits/stdc++.h"
#include "crocodile.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
const int mxN = 1e5+1;
const ll oo = 1e18;
struct el {
int at,from;
ll d;
bool operator<(const el& o) const {
return d>o.d;
}
};
ll dijkstra(int n,const vvpi& adj, const vi& starts, vi& best, bool forbid=false) {
vector<ll> dist(n,oo);
priority_queue<el> pq;
for(auto& i : starts) {
pq.push({i,i,0});
dist[i]=0;
}
while(!pq.empty()) {
auto c = pq.top(); pq.pop();
if(c.d>dist[c.at]) continue;
if(!forbid and c.at!=c.from) {
best[c.at] = c.from;
}
for(auto [to,w] : adj[c.at]) {
if(forbid and best[to]==c.at) continue;
auto tmp = w+c.d;
if(dist[to]>tmp) {
dist[to] = tmp;
pq.push(el{to,c.at,tmp});
}
}
}
return dist[0];
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
vvpi adj(N);
for(int i=0;i<M;++i) {
int a = R[i][0], b= R[i][1];
adj[a].emplace_back(b,L[i]);
adj[b].emplace_back(a,L[i]);
}
vi exits(P,P+K);
vi best(N,-1);
dijkstra(N,adj,exits,best);
return dijkstra(N,adj,exits,best,true);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |