#include "crocodile.h"
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]);
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
long long dist[N][2];
for(int i=0; i<N; i++) dist[i][0] = dist[i][1] = 1e15;
for(int i=0; i<K; i++) dist[P[i]][0] = dist[P[i]][1] = 0;
bool vis[N];
for(int i=0; i<N; i++) vis[i] = 0;
priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > >pq;
for(int i=0; i<N; i++) pq.push({dist[i][1], i});
vector<pair<int, long long> > adj[N];
for(int i=0; i<M; i++) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
while(pq.size()) {
pair<long long, int> t = pq.top(); pq.pop();
if(!vis[t.second]) {
vis[t.second] = 1;
for(pair<int, long long> x : adj[t.second]) {
if(!vis[x.first] && dist[t.second][1] != 1e15) {
int now = dist[t.second][1] + x.second;
if(now >= dist[x.first][0] && now < dist[x.first][1]) {
dist[x.first][1] = now;
pq.push({dist[x.first][1], x.first});
}
else if(now < dist[x.first][0]) {
dist[x.first][1] = dist[x.first][0];
dist[x.first][0] = now;
pq.push({dist[x.first][1], x.first});
}
}
}
}
}
return (int)dist[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 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 |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 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 |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
844 KB |
Output is correct |
13 |
Correct |
3 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 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 |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
844 KB |
Output is correct |
13 |
Correct |
3 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
439 ms |
67364 KB |
Output is correct |
17 |
Correct |
97 ms |
21812 KB |
Output is correct |
18 |
Correct |
131 ms |
24328 KB |
Output is correct |
19 |
Correct |
589 ms |
93328 KB |
Output is correct |
20 |
Correct |
292 ms |
65892 KB |
Output is correct |
21 |
Correct |
45 ms |
9112 KB |
Output is correct |
22 |
Correct |
292 ms |
63332 KB |
Output is correct |