#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) {
vector<ar<int,2>> g[n];
for (int i = 0; i < m; i++) {
g[R[i][0]].push_back({L[i], R[i][1]});
g[R[i][1]].push_back({L[i], R[i][0]});
}
priority_queue<ar<int,2>, vector<ar<int,2>>, greater<ar<int,2>>> pq;
vector<int> dist(n, -1);
for (int i = 0; i < k; i++) pq.push({0,P[i]});
while (!pq.empty()) {
int u = pq.top()[1], d = pq.top()[0]; pq.pop();
if (dist[u] != -1) continue;
dist[u] = d;
for (auto v : g[u]) if (dist[v[1]] == -1) {
pq.push({d + v[0], v[1]});
}
}
for (int i = 0; i < n; i++)
sort(g[i].begin(), g[i].end(), [&](ar<int,2> a, ar<int,2> b) { return dist[a[1]] + a[0] < dist[b[1]] + b[0]; });
int u = 0, pu = -1, res = 0;
while (dist[u] != 0) {
//cout<<u<<" "<<pu<<endl;
for (int i = 1; i < g[u].size(); i++) {
auto v = g[u][i];
if (v[1] == pu) continue;
res += v[0];
pu = u; u = v[1];
break;
}
}
//cout<<u<<endl;
return res;
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 1; i < g[u].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |