#include <bits/stdc++.h>
#include "crocodile.h"
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
const ll INF = 1e17;
vector<vector<ll>> plan;
vector<vector<pi>> adj_list;
vector<bool> visited;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
adj_list.resize(N);
for (int i = 0; i < M; i++) {
adj_list[R[i][0]].pb(mp(R[i][1], L[i]));
adj_list[R[i][1]].pb(mp(R[i][0], L[i]));
}
plan.assign(N, vector<ll>(2, INF));
visited.assign(N, false);
priority_queue<pi, vector<pi>, greater<pi>> q;
for (int i = 0; i < K; i++) {
plan[P[i]][0] = plan[P[i]][1] = 0;
q.push(mp(0, P[i]));
}
while (!q.empty()) {
int v = q.top().s;
q.pop();
if (visited[v])
continue;
visited[v] = true;
for (auto u : adj_list[v]) {
ll curd = plan[v][1] + u.s;
if (plan[u.f][0] > curd) {
plan[u.f][1] = plan[u.f][0];
plan[u.f][0] = curd;
if (plan[u.f][1] != INF)
q.push(mp(plan[u.f][1], u.f));
}
else if (plan[u.f][1] > curd) {
plan[u.f][1] = curd;
q.push(mp(plan[u.f][1], u.f));
}
}
}
return plan[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
360 KB |
Output is correct |
16 |
Correct |
390 ms |
56360 KB |
Output is correct |
17 |
Correct |
67 ms |
18380 KB |
Output is correct |
18 |
Correct |
92 ms |
19528 KB |
Output is correct |
19 |
Correct |
537 ms |
63072 KB |
Output is correct |
20 |
Correct |
258 ms |
47340 KB |
Output is correct |
21 |
Correct |
33 ms |
7344 KB |
Output is correct |
22 |
Correct |
268 ms |
45668 KB |
Output is correct |