#include "crocodile.h"
#include <vector>
#include <utility>
using namespace std;
#define INF 9999999999
vector<vector<pair<int, int>>> tree;
vector<long long> times;
vector<int> visited;
void dfs(int n)
{
if(visited[n])
return;
else
visited[n] = 1;
if(times[n] == 0)
return;
vector<long long> temp;
for(int i = 0; i < tree[n].size(); i++)
{
dfs(tree[n][i].first);
temp.push_back(times[tree[n][i].first] + tree[n][i].second);
}
long long minInd, curMin = INF;
for(int i = 0; i < temp.size(); i++)
{
if(curMin > temp[i])
{
curMin = temp[i];
minInd = i;
}
}
curMin = INF;
for(int i = 0; i < temp.size(); i++)
{
if(curMin > temp[i] && i != minInd)
curMin = temp[i];
}
if(curMin >= INF)
times[n] = INF;
else
times[n] = curMin;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
tree.assign(N, vector<pair<int, int>>());
times.assign(N, INF);
visited.assign(N, 0);
for(int i = 0; i < N - 1; i++)
{
tree[R[i][0]].push_back(make_pair(R[i][1], L[i]));
tree[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < K; i++)
times[P[i]] = 0;
dfs(0);
return (int)times[0];
}
Compilation message
crocodile.cpp: In function 'void dfs(int)':
crocodile.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i = 0; i < tree[n].size(); i++)
| ~~^~~~~~~~~~~~~~~~
crocodile.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < temp.size(); i++)
| ~~^~~~~~~~~~~~~
crocodile.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < temp.size(); i++)
| ~~^~~~~~~~~~~~~
crocodile.cpp:43:29: warning: 'minInd' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | if(curMin > temp[i] && i != minInd)
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |