#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
vector<vector<vector<ll>>> v;
vector<ll> vis, dp, isw;
void dfs(int x, ll co){
vis[x] = 1;
vector<ll> pus = {INF};
if (isw[x] == 1){
dp[x] = co;
return;
}
for (auto el : v[x]){
if (vis[el[1]] == 0){
dfs(el[1], co + el[0]);
pus.push_back(dp[el[1]]);
}
}
ll mi = INF, smi = INF;
for (int i = 0; i < pus.size(); i++){
if (pus[i] <= mi){
smi = mi;
mi = pus[i];
}
else if (pus[i] <= smi){
smi = pus[i];
}
}
dp[x] = smi;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
v.resize(N), vis.assign(N, 0), dp.assign(N, 0), isw.assign(N, 0);
for (int i = 0; i < M; i++){
v[R[i][0]].push_back({L[i], R[i][1]});
v[R[i][1]].push_back({L[i], R[i][0]});
}
for (int i = 0; i < N; i++){
dp[i] = 0;
sort(v[i].begin(), v[i].end());
}
for (int i = 0; i < K; i++){
isw[P[i]] = 1;
}
dfs(0, 0);
return dp[0];
}
Compilation message
crocodile.cpp: In function 'void dfs(int, long long int)':
crocodile.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < pus.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
712 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
712 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
712 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |