#include "crocodile.h"
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define int long long
int n, m;
const int MXN = 100005;
vector<pair<int, int> > adj[MXN];
bool ter[MXN], assign[MXN];
int dist[MXN];
int via[MXN];
int gdis[MXN];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pro, gpr;
void gdi() {
for (int i=0; i<MXN; i++) gdis[i] = INT_MAX;
while (!gpr.empty()) {
int di = gpr.top().first;
int no = gpr.top().second;
gpr.pop();
if (gdis[no] < di) continue;
gdis[no] = di;
for (int i=0; i<adj[no].size(); i++) {
int o = adj[no][i].first;
int od = adj[no][i].second + di;
if (gdis[o] > od) {
gdis[o] = od;
gpr.push(make_pair(od, o));
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n = N, m = M;
for (int i=0; i<m; i++) {
int a, b, w;
a = R[i][0], b = R[i][1], w = L[i];
adj[a].push_back(make_pair(b, w));
adj[b].push_back(make_pair(a, w));
}
int poss[MXN];
memset(poss, 0, sizeof poss);
bool done[MXN];
for (int i=0; i<MXN; i++) dist[i] = INT_MAX;
int k = K;
for (int i=0; i<k; i++) {
int x = P[i];
ter[x] = true;
dist[x] = 0;
done[x] = true;
pro.push(make_pair(0, x));
gpr.push(make_pair(0, x));
}
gdi();
vector<int> towa[MXN];
while (!pro.empty()) {
int di = pro.top().first;
int no = pro.top().second;
pro.pop();
if (dist[no] < di) continue; // do not relax
if (poss[no] >= 2) {
// can be calculated now
// but what if more relaxations are pending
vector<int> ch;
for (int i=0; i<adj[no].size(); i++) {
int o = adj[no][i].first;
if (done[o]) {
ch.push_back(dist[o] + adj[no][i].second);
}
}
sort(ch.begin(), ch.end());
dist[no] = ch[1];
done[no] = true;
}
if (done[no] && !assign[no]) {
assign[no] = true;
for (int i=0; i<adj[no].size(); i++) {
int o = adj[no][i].first;
if (!done[o]) {
poss[o]++;
towa[o].push_back(dist[no] + adj[no][i].second);
if (poss[o] >= 2) pro.push(make_pair(gdis[no] + adj[no][i].second, o));
}
}
}
}
assert(dist[0] != INT_MAX);
return dist[0];
}
Compilation message
crocodile.cpp: In function 'void gdi()':
crocodile.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<adj[no].size(); i++) {
~^~~~~~~~~~~~~~~
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<adj[no].size(); i++) {
~^~~~~~~~~~~~~~~
crocodile.cpp:92:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<adj[no].size(); i++) {
~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Output is correct |
2 |
Incorrect |
7 ms |
6272 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Output is correct |
2 |
Incorrect |
7 ms |
6272 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Output is correct |
2 |
Incorrect |
7 ms |
6272 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |