#include "crocodile.h"
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define f first;
#define s second;
#define oo 1000000000
vector<vector<pii>> ed;
vector<bool> ext;
vector<bool> visited;
vector<int> res;
int dfs(int v, int pr, int d){
visited[v] = true;
vector<int> cur;
for (auto [x, l] : ed[v]){
if (x == pr) continue;
if (ext[x]) cur.pb(d + l);
else if (visited[x]) cur.pb(res[x]);
else cur.pb(dfs(x, v, d + l));
}
sort(cur.begin(), cur.end());
if (cur.size() <= 1) return res[v] = oo;
return res[v] = cur[1];
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
ed.resize(n);
ext.resize(n);
visited.resize(n);
res.resize(n);
for (int i = 0; i < m; ++i) {
ed[r[i][0]].pb({r[i][1], l[i]});
ed[r[i][1]].pb({r[i][0], l[i]});
}
for (int i = 0; i < k; ++i) {
ext[p[i]] = true;
}
int ans = dfs(0, -1, 0);
return ans;
}
Compilation message
crocodile.cpp: In function 'int dfs(int, int, int)':
crocodile.cpp:21:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
21 | for (auto [x, l] : ed[v]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Incorrect |
4 ms |
560 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Incorrect |
4 ms |
560 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |