#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const ll INF=1e18+1;
int travel_plan(int N, int M, int R[][2], int S[], int K, int P[]){
vector<vector<pair<int,ll> > > listaAdy(N);
for (int i=0; i<M; i++){
listaAdy[R[i][0]].push_back(make_pair(R[i][1], S[i]));
listaAdy[R[i][1]].push_back(make_pair(R[i][0], S[i]));
}
vector<pair<ll,ll> > dist(N, make_pair(INF, INF));
priority_queue<pair<ll, int> >pq;
for (int i=0; i<K; i++){
dist[P[i]].first=0;
dist[P[i]].second=0;
pq.push(make_pair(0, P[i]));
}
while (!pq.empty()){
int u=pq.top().second;
ll d=-pq.top().first;
pq.pop();
if (dist[u].second<d) continue;
if (dist[u].first<=d) dist[u].second=d;
else{
dist[u].second=dist[u].first;
dist[u].first=d;
}
if (dist[u].second==INF) continue;
for (auto vec: listaAdy[u]){
int v=vec.first;
ll c=vec.second;
ll dact=dist[u].second+c;
if(dist[v].second>dact){
if (dist[v].second==dist[v].first){
dist[v].first=dact;
continue;
}
dist[v].second=dact;
if (dist[v].second<dist[v].first){
dist[v].second=dist[v].first;
dist[v].first=dact;
}pq.push(make_pair(-dist[v].second, v));
}
}
}
if (dist[0].second==INF) return -1;
return dist[0].second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 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 |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 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 |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
3 ms |
5056 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 |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 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 |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
3 ms |
5056 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
317 ms |
66060 KB |
Output is correct |
17 |
Correct |
53 ms |
16212 KB |
Output is correct |
18 |
Correct |
73 ms |
18256 KB |
Output is correct |
19 |
Correct |
393 ms |
73976 KB |
Output is correct |
20 |
Correct |
219 ms |
53436 KB |
Output is correct |
21 |
Correct |
27 ms |
9812 KB |
Output is correct |
22 |
Correct |
234 ms |
50268 KB |
Output is correct |