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) {
vector<ll> dist(n,oo);
vi visited(n);
priority_queue<el> pq;
for(auto& i : starts) {
pq.push({i,i,0});
visited[i] = 1;
dist[i]=0;
}
while(!pq.empty()) {
auto c = pq.top(); pq.pop();
if(c.d>dist[c.at]) continue;
if(!visited[c.at]) {
visited[c.at]=1;
continue;
}
if(visited[c.at]==2) continue;
visited[c.at]=2;
dist[c.at] = c.d;
for(auto [to,w] : adj[c.at]) {
auto tmp = w+c.d;
if(visited[to]==2) continue;
pq.push({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(K);
for(int i=0;i<K;++i) exits[i] = P[i];
return dijkstra(N,adj,exits);
}
Compilation message (stderr)
crocodile.cpp: In function 'll dijkstra(int, const vvpi&, const vi&)':
crocodile.cpp:42:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | 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... |