#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
bool is_exit[MAX_N];
vector<pair<int, long long>> g[MAX_N];
long long solve(int u, int p) {
if (is_exit[u]) {
assert(g[u].size() == 1);
return 0;
}
long long mn_1 = 2e9, mn_2 = 2e9;
for (pair<int, long long> edge : g[u]) {
if (edge.first == p) continue;
long long res = solve(edge.first, u) + edge.second;
if (res < mn_1) {
mn_2 = mn_1;
mn_1 = res;
}
else {
mn_2 = min(mn_2, res);
}
}
return mn_2;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
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] });
}
for (int i=0 ; i<K ; i++) {
is_exit[P[i]] = true;
}
return solve(0, -1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6808 KB |
Output is correct |
4 |
Correct |
1 ms |
6788 KB |
Output is correct |
5 |
Correct |
1 ms |
6796 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6808 KB |
Output is correct |
4 |
Correct |
1 ms |
6788 KB |
Output is correct |
5 |
Correct |
1 ms |
6796 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Runtime error |
8 ms |
13916 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6808 KB |
Output is correct |
4 |
Correct |
1 ms |
6788 KB |
Output is correct |
5 |
Correct |
1 ms |
6796 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Runtime error |
8 ms |
13916 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |