#include "crocodile.h"
#include <iostream>
#include <vector>
#include <utility>
#include <set>
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;
set<long long> s;
for(int i = 0; i < tree[n].size(); i++)
{
dfs(tree[n][i].first);
s.insert(times[tree[n][i].first] + tree[n][i].second);
}
if(s.size() < 2 || *(++s.begin()) >= INF)
times[n] = INF;
else
times[n] = *(++s.begin());
}
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:26: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]
26 | for(int i = 0; i < tree[n].size(); i++)
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |