#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
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 |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
5 ms |
1100 KB |
Output is correct |
13 |
Correct |
5 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
5 ms |
1100 KB |
Output is correct |
13 |
Correct |
5 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
803 ms |
71520 KB |
Output is correct |
17 |
Correct |
81 ms |
14020 KB |
Output is correct |
18 |
Correct |
116 ms |
15584 KB |
Output is correct |
19 |
Correct |
874 ms |
75944 KB |
Output is correct |
20 |
Correct |
493 ms |
63788 KB |
Output is correct |
21 |
Correct |
40 ms |
6080 KB |
Output is correct |
22 |
Correct |
429 ms |
45216 KB |
Output is correct |