#include "crocodile.h"
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#define MAXN 100005
using namespace std;
vector<pair<int,int> > adj[MAXN];
int dp[MAXN], dp2[MAXN], C[MAXN]; //min, second min, number of adj
bool vis[MAXN], done[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] = dp2[i] = 1e9 + 10;
}
for (int i=0; i<K; i++) {
dp[P[i]] = dp2[P[i]] = 0;
vis[P[i]] = 1;
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;
PQ.pop();
if (done[cur]) {continue;}
done[cur] = true;
for (auto v: adj[cur]) {
if (!done[v.first]) {
if (!C[v.first]) {
dp[v.first] = dp2[cur] + v.second;
} else {
dp2[v.first] = min(dp2[v.first], dp2[cur] + v.second);
if (dp[v.first] > dp2[v.first]) {
swap(dp[v.first], dp2[v.first]);
}
}
C[v.first] += 1;
if (C[v.first] >= 2) {PQ.push({-dp2[v.first], v.first});}
}
}
}
return(dp2[0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Incorrect |
8 ms |
2944 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Incorrect |
8 ms |
2944 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |