#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<long long,long long> LL;
const ll N = 1e5 + 9;
const long long inf = 1e9;
//#include "crocodile.h"
vector<ll> vec;
vector<LL> g[N];
LL d[N];
ll ans;
struct Node{
long long cur,w1,w2;
};
bool operator < (Node a,Node b){
return a.w2 < b.w2||(a.w2 == b.w2 && a.w1 < b.w1)||(a.w2 == b.w2 && a.w1 == b.w1 && a.cur < b.cur);
}
set<Node> s;
void update(LL &x,long long y){
if (x.fs >= y) x.sc = x.fs,x.fs = y;
else if (x.sc > y) x.sc = y;
}
void Dij(ll n){
for (ll i = 0;i < n;i++) d[i] = {inf,inf};
for (auto i : vec) d[i] = {0,0},s.insert({i,0,0});
while(!s.empty()){
Node t = *s.begin(); s.erase(s.begin());
ll u = t.cur,cost = t.w2;
for (auto i : g[u]){
ll v = i.fs,L = i.sc;
if (d[v].sc > cost + L){
s.erase({v,d[v].fs,d[v].sc});
update(d[v],cost + L); s.insert({v,d[v].fs,d[v].sc});
}
}
}
ans = d[0].sc;
}
ll travel_plan(ll n,ll m,ll R[][2],ll lens[],ll k,ll a[]){
for (ll i = 0;i < k;i++) vec.push_back(a[i]);
for (ll i = 0;i < m;i++){
ll u = R[i][0],v = R[i][1],L = lens[i];
g[u].push_back({v,L}); g[v].push_back({u,L});
}
Dij(n); return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
3020 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2844 KB |
Output is correct |
12 |
Correct |
6 ms |
3280 KB |
Output is correct |
13 |
Correct |
5 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
3020 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2844 KB |
Output is correct |
12 |
Correct |
6 ms |
3280 KB |
Output is correct |
13 |
Correct |
5 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
16 |
Correct |
738 ms |
80792 KB |
Output is correct |
17 |
Correct |
90 ms |
17540 KB |
Output is correct |
18 |
Correct |
172 ms |
20052 KB |
Output is correct |
19 |
Correct |
1281 ms |
84980 KB |
Output is correct |
20 |
Correct |
325 ms |
67980 KB |
Output is correct |
21 |
Correct |
51 ms |
9740 KB |
Output is correct |
22 |
Correct |
383 ms |
64016 KB |
Output is correct |