#include <bits/stdc++.h>
#include "crocodile.h"
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> grafo[MAXN], pesos[MAXN];
int Dist[MAXN];
int pai[MAXN], pai2[MAXN];
int DPai[MAXN], Dpai2[MAXN];
vector<int> process;
void dijkstra(int N)
{
set<pair<int, int> > fora;
for (int i = 0; i < N; i++)
{
fora.emplace(INF, i);
Dist[i] = INF;
Dpai2[i] = DPai[i] = INF;
}
for (auto p : process)
{
pai2[p] = pai[p] = p;
Dist[p] = 0;
Dpai2[p] = DPai[p] = -INF;
fora.erase(make_pair(INF, p));
fora.emplace(0, p);
}
// DPai[0] = Dpai2[0] = -INF;
while (!fora.empty())
{
int cur = fora.begin()->second; fora.erase(fora.begin());
if (cur == 0) continue;
// cerr << fora.size() << '\n';
for (int i = 0; i < grafo[cur].size(); i++)
{
int viz = grafo[cur][i];
int p = pesos[cur][i];
if (Dist[cur] + p <= Dist[viz])
{
// cerr << cur << " novo pai de " << viz << '\n';
pai2[viz] = pai[viz];
Dpai2[viz] = DPai[viz];
pai[viz] = cur;
DPai[viz] = p;
fora.erase(make_pair(Dist[viz], viz));
Dist[viz] = Dist[cur] + p;
fora.emplace(Dist[viz], viz);
}
else if (Dist[cur] + p <= Dist[pai2[viz]] + Dpai2[viz])
{
// cerr << cur << " novo pai2 de " << viz << '\n';
Dpai2[viz] = p;
pai2[viz] = cur;
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i = 0; i < M; i++)
{
int X = R[i][0]; int Y = R[i][1];
int P = L[i];
// cerr << X << " " << Y << " " << P << '\n';
grafo[X].push_back(Y);
pesos[X].push_back(P);
grafo[Y].push_back(X);
pesos[Y].push_back(P);
}
for (int k = 0; k < K; k++) process.push_back(P[k]);
pai2[0] = 0;
dijkstra(N);
int x = 0; int dist = 0;
while (pai2[x] != x)
{
dist += Dpai2[x];
// cerr << pai2[x] << " " << Dpai2 << '\n';
x = pai2[x];
}
return dist;
}
Compilation message
crocodile.cpp: In function 'void dijkstra(int)':
crocodile.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < grafo[cur].size(); i++)
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |