#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define int long long
int n, m;
const int MXN = 100005;
vector<pair<int, int> > adj[MXN];
bool ter[MXN];
int dist[MXN];
int via[MXN];
int best(int node, int last) {
if (ter[node]) return 0;
vector<int> opts;
for (int i=0; i<adj[node].size(); i++) {
int f = adj[node][i].first, s = adj[node][i].second;
if (f == last) continue;
opts.push_back(s + best(f, node));
}
sort(opts.begin(), opts.end());
return opts[1];
}
#include "crocodile.h"
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n = N;
m = M;
for (int i=0; i<m; i++) {
int a = R[i][0], b = R[i][1], w = L[i];
adj[a].push_back(make_pair(b, w));
adj[b].push_back(make_pair(a, w));
}
int k;
cin >> k;
for (int i=0; i<k; i++) {
int x = P[i];
ter[x] = true;
}
return best(0, -1);
}
Compilation message
crocodile.cpp: In function 'int best(int, int)':
crocodile.cpp:16:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<adj[node].size(); i++) {
~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
5248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
5248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
5248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |