#include "crocodile.h"
#include <iostream>
#include <vector>
#include <queue>
#include<set>
#include <utility>
#define MAXN 100005
using namespace std;
vector<pair<int,int> > adj[MAXN];
int dp[MAXN]; //min, second min, number of adj
bool done[MAXN];
set <int> V[MAXN];
priority_queue <pair<int,int> > PQ;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i=0; i<N; i++) {
dp[i] = 2e9 + 10;
}
for (int i=0; i<K; i++) {
dp[P[i]] = 0;
PQ.push({0,P[i]});
}
for (int i=0; i<M; i++) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
while (PQ.size()) {
int cur = PQ.top().second;
dp[cur] = min(dp[cur], -PQ.top().first);
PQ.pop();
if (done[cur]) {continue;}
done[cur] = true;
for (auto v: adj[cur]) {
if (!done[v.first]) {
V[v.first].insert(dp[cur] + v.second);
if (V[v.first].size() >= 2) {
auto it = ++V[v.first].begin();
PQ.push({-(*it), v.first});
}
}
}
}
return(dp[0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Incorrect |
9 ms |
7552 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Incorrect |
9 ms |
7552 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Incorrect |
9 ms |
7552 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |