#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
ll n, m, k;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
n = N; m = M; k = K;
vector<vector<pii>> v(n, vector<pii>());
for (int i = 0; i < m; i++) v[R[i][0]].emplace_back(R[i][1], L[i]), v[R[i][1]].emplace_back(R[i][0], L[i]);
vector<bool> ok(n);
for (int i = 0; i < k; i++) ok[P[i]] = 1;
vector<int> dp(n);
function<void(int, int)> dfs = [&] (int cur, int par) {
bool isleaf = 1;
vector<int> u;
for (auto &[x, y]: v[cur]) {
if (par == x) continue; isleaf = 0;
dfs(x, cur);
u.emplace_back(dp[x] + y);
}
sort(u.begin(), u.end());
if (u.size() == 1) dp[cur] = 1e9;
else if (u.size() > 1) dp[cur] = u[1];
if (isleaf) dp[cur] = ok[cur] ? dp[cur] : 1e9;
};
dfs(0, -1);
return dp[0];
}
Compilation message
crocodile.cpp: In lambda function:
crocodile.cpp:21:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
21 | if (par == x) continue; isleaf = 0;
| ^~
crocodile.cpp:21:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
21 | if (par == x) continue; isleaf = 0;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
3 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 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 |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
3 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 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 |
4700 KB |
Output is correct |
9 |
Runtime error |
177 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
3 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 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 |
4700 KB |
Output is correct |
9 |
Runtime error |
177 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |