#include "crocodile.h"
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
ll dijkstra(vector<int> starts, vector<vector<pair<int, ll>>> adj)
{
int n = adj.size();
vector<pair<ll, ll>> dist(n, {1e12, 1e12});
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
vector<bool> used(n);
for (int i : starts)
{
dist[i].first = dist[i].second = 0;
pq.push({0, i});
}
while (!pq.empty())
{
int v = pq.top().second;
pq.pop();
if (used[v]) continue;
used[v] = true;
for (auto [u, w] : adj[v])
{
if (dist[u].first > dist[v].second + w)
{
dist[u].second = dist[u].first;
dist[u].first = dist[v].second + w;
if (dist[u].second != 1e12) pq.push({dist[u].second, u});
}
else if (dist[u].second > dist[v].second + w)
{
dist[u].second = dist[v].second + w;
pq.push({dist[u].second, u});
}
}
}
return dist[0].second;
}
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
vector<int> starts(k);
for (int i = 0; i < k; ++i) starts[i] = P[i];
vector<vector<pair<int, ll>>> adj(n);
for (int i = 0; i < m; ++i)
{
adj[R[i][0]].emplace_back(R[i][1], L[i]);
adj[R[i][1]].emplace_back(R[i][0], L[i]);
}
return dijkstra(starts, adj);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
436 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 |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
436 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 |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
1364 KB |
Output is correct |
13 |
Correct |
3 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
436 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 |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
1364 KB |
Output is correct |
13 |
Correct |
3 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
466 ms |
109712 KB |
Output is correct |
17 |
Correct |
87 ms |
27744 KB |
Output is correct |
18 |
Correct |
107 ms |
29544 KB |
Output is correct |
19 |
Correct |
618 ms |
119692 KB |
Output is correct |
20 |
Correct |
292 ms |
96980 KB |
Output is correct |
21 |
Correct |
40 ms |
12036 KB |
Output is correct |
22 |
Correct |
341 ms |
91716 KB |
Output is correct |