This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
Compilation message (stderr)
crocodile.cpp: In function 'll dijkstra(int, const vvpi&, const vi&, vi&, bool)':
crocodile.cpp:36:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | for(auto [to,w] : adj[c.at]) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |