#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const long long maxn = 100005;
const long long maxv = (long long) 1e18;
long long n,m,k,val[maxn][2];
bool beenTo[maxn];
vector<pair<long long,long long> > conn[maxn];
priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > dijkstra;
int travel_plan(int N, int M, int R[][2], int W[], int K, int E[]) {
n = N;
m = M;
k = K;
for(int i = 0; i < m; i++) {
int a = R[i][0];
int b = R[i][1];
int c = W[i];
conn[a].push_back(make_pair(c,b));
conn[b].push_back(make_pair(c,a));
}
for(int i = 0; i < k; i++) {
int a = E[i];
val[a][0] = 0;
val[a][1] = 0;
dijkstra.push(make_pair(0,a));
}
for(long long i = 0; i < n; i++) {
val[i][0] = maxv;
val[i][1] = maxv;
}
while(dijkstra.size() > 0) {
pair<long long,long long> curr = dijkstra.top();
dijkstra.pop();
if(beenTo[curr.second] == true) continue;
beenTo[curr.second] = true;
for(long long i = 0; i < conn[curr.second].size(); i++) {
pair<long long,long long> targ = conn[curr.second][i];
if(val[targ.second][0] > val[curr.second][1]+targ.first) {
val[targ.second][1] = val[targ.second][0];
val[targ.second][0] = val[curr.second][1]+targ.first;
dijkstra.push(make_pair(val[targ.second][1],targ.second));
}
else if(val[targ.second][1] > val[curr.second][1]+targ.first) {
val[targ.second][1] = val[curr.second][1]+targ.first;
dijkstra.push(make_pair(val[targ.second][1],targ.second));
}
}
}
return val[0][1];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:37:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(long long i = 0; i < conn[curr.second].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |