#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector <vector <pair <int, int>>> adj;
vector <bool> is_exit;
ll dfs(int s, int p) {
if (adj[s].size() == 1 && s != p)
return 0;
vector <ll> x;
for (auto i : adj[s]) {
if (i.first == p)
continue;
x.push_back(dfs(i.first, s) + i.second);
}
sort(x.begin(), x.end());
return x[1];
}
int travel_plan(int N, int M, int R[][2], int W[], int K, int P[]) {
adj.resize(N+1);
is_exit = vector <bool> (N+1);
for (int i = 0; i < M; i++) {
int a = R[i][0], b = R[i][1];
int w = W[i];
adj[a].push_back({b, w});
adj[b].push_back({a, w});
}
for (int i = 0; i < K; i++)
is_exit[P[i]] = true;
if (M > N-1)
return 0;
return dfs(0, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |