#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
int degree[MAX_N];
long long mn_1[MAX_N], mn_2[MAX_N];
bool is_process[MAX_N];
vector<pair<int, long long>> g[MAX_N];
void update(int u, long long v) {
if (v < mn_1[u]) {
mn_2[u] = mn_1[u];
mn_1[u] = v;
}
else {
mn_2[u] = min(mn_2[u], v);
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i=0 ; i<N ; i++) {
mn_1[i] = mn_2[i] = 2e9;
}
for (int i=0 ; i<M ; i++) {
g[R[i][0]].push_back({ R[i][1], L[i] });
g[R[i][1]].push_back({ R[i][0], L[i] });
degree[R[i][0]]++;
degree[R[i][1]]++;
}
queue<int> topo;
for (int i=0 ; i<K ; i++) {
is_process[P[i]] = true;
topo.push(P[i]);
mn_1[P[i]] = mn_2[P[i]] = 0;
}
while (!topo.empty()) {
int u = topo.front();
topo.pop();
for (pair<int, long long> edge : g[u]) {
degree[edge.first]--;
update(edge.first, mn_2[u] + edge.second);
if (!is_process[edge.first] && degree[edge.first] == 1) {
is_process[edge.first] = true;
topo.push(edge.first);
}
}
}
return mn_2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2872 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2872 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2872 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |