#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int INF = 1000000001;
vector<pair<int, int> > graph[MAX_N];
int dp[MAX_N];
bool proc[MAX_N];
void dfs(int nod) {
if(!proc[nod] && dp[nod] == INF) {
int best[2];
proc[nod] = true;
best[0] = best[1] = INF;
for(auto it: graph[nod]) {
dfs(it.first);
int cost = dp[it.first] + it.second;
if(cost <= best[0]) {
best[1] = best[0];
best[0] = cost;
} else if(cost <= best[1])
best[1] = cost;
}
dp[nod] = best[1];
proc[nod] = false;
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for(int i = 0; i < M; ++i) {
graph[R[i][0]].push_back(make_pair(R[i][1], L[i]));
graph[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < N; ++i)
dp[i] = INF;
for(int i = 0; i < K; ++i) {
dp[P[i]] = 0;
proc[P[i]] = true;
}
dfs(0);
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
0 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
0 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2944 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Incorrect |
6 ms |
2816 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
0 ms |
2688 KB |
Output is correct |
4 |
Correct |
5 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2944 KB |
Output is correct |
10 |
Correct |
4 ms |
2688 KB |
Output is correct |
11 |
Incorrect |
6 ms |
2816 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |