#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const long long INF = 1e15;
vector<pair<int, int> > g[MAXN];
set<int> exit_chambers;
long long dp[MAXN];
bool vis[MAXN];
void dfs(int node, int par) {
if(dp[node] != -1 || vis[node]) {
return;
}
if(exit_chambers.count(node)) {
dp[node] = 0;
return;
}
vis[node] = true;
long long max_val = INF, second_max_val = INF;
for(int i = 0; i < g[node].size(); i++) {
dfs(g[node][i].first, node);
if(dp[g[node][i].first] == -1) {
continue;
}
if(max_val > dp[g[node][i].first] + g[node][i].second) {
second_max_val = max_val;
max_val = dp[g[node][i].first] + g[node][i].second;
}
else if(second_max_val > dp[g[node][i].first] + g[node][i].second) {
second_max_val = dp[g[node][i].first] + g[node][i].second;
}
}
dp[node] = second_max_val;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < N + 5; i++) {
dp[i] = -1;
vis[i] = false;
}
for(int i = 0; i < M; i++) {
g[R[i][0]].push_back(make_pair(R[i][1], L[i]));
g[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < K; i++) {
exit_chambers.insert(P[i]);
}
dfs(0, -1);
return (int)(dp[0]);
}
Compilation message
crocodile.cpp: In function 'void dfs(int, int)':
crocodile.cpp:22: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]
22 | for(int i = 0; i < g[node].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
2856 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
2856 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |