#include "crocodile.h"
#ifdef LOCAL
#include "crocodile_grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG
const int maxn = 1e3 + 5, inf = 1e9;
int sol[maxn];
bool ex[maxn];
vector<pair<int, int>> adj[maxn];
void dfs(int c, int p) {
vector<int> pos;
for (auto i : adj[c]) {
if (i.first != p) {
dfs(i.first, c);
pos.push_back(sol[i.first] + i.second);
}
}
sort(pos.begin(), pos.end());
if (pos.size() <= 1) {
sol[c] = -inf;
} else {
sol[c] = pos[1];
}
if (ex[c]) {
sol[c] = 0;
}
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
for (int i = 0; i < m; ++i) {
int a = r[i][0], b = r[i][1], cost = l[i];
adj[a].emplace_back(b, cost);
adj[b].emplace_back(a, cost);
}
for (int i = 0; i < k; ++i) {
ex[p[i]] = true;
}
for (int i = 0; i < n; ++i) {
sol[i] = -inf;
}
dfs(0, -1);
return sol[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Runtime error |
177 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Runtime error |
177 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |