#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
template<typename T>
int len(T &a){return a.size();}
const int inf = 1e9 + 1;
const ll infl = 1e9;
#define ss second
#define ff first
#define all(a) (a).begin(), (a).end()
int travel_plan(int n, int m, int r[][2], int L[], int K, int P[])
{
vector<vector<pair<int,int>>> g(n);
//cout << "done" << endl;
for(int i = 0; i < m; i ++){
g[r[i][0]].push_back({r[i][1], L[i]});
g[r[i][1]].push_back({r[i][0], L[i]});
}
vector<pair<ll, ll>> dis(n, {infl, infl});
priority_queue<pair<ll, int>> q;
for(int i = 0; i < K; i ++){
q.push({0, P[i]});
dis[P[i]] = {0, 0};
}
vector<int> vis(n);
while(!q.empty()){
int t = q.top().ss;
q.pop();
if(vis[t]) continue;
vis[t] = 1;
for(auto [u, w] : g[t]){
if(dis[u].ff > dis[t].ss + w){
dis[u].ss = dis[u].ff;
q.push({-dis[u].ss, u});
dis[u].ff = dis[t].ss + w;
}else if(dis[u].ss > dis[t].ss + w){
dis[u].ss = dis[t].ss + w;
q.push({-dis[u].ss, u});
}
}
}
return dis[0].ss;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4544 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4828 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4544 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4828 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
246 ms |
41504 KB |
Output is correct |
17 |
Correct |
55 ms |
13872 KB |
Output is correct |
18 |
Correct |
71 ms |
14896 KB |
Output is correct |
19 |
Correct |
308 ms |
48664 KB |
Output is correct |
20 |
Correct |
161 ms |
35000 KB |
Output is correct |
21 |
Correct |
31 ms |
8284 KB |
Output is correct |
22 |
Correct |
180 ms |
32432 KB |
Output is correct |