#include "crocodile.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iterator>
#include <set>
#include <map>
#include <math.h>
#include <iomanip>
#include <unordered_set>
#include <queue>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
vector<vector<pair<int,int>>> adj;
vector<int> dp;
void dfs(int u, int p){
if (adj[u].size() == 1){
dp[u] = 0;
return;
}
for (auto [v, w] : adj[u]){
if (v != p) dfs(v, u);
}
int min1 = INT_MAX, min2 = INT_MAX;
for (auto [v, w] : adj[u]){
if (v == p) continue;
int val = dp[v] + w;
if (val < min1){
min2 = min1;
dp[u] = min1;
min1 = val;
}
else if (min1 < val && val < min2){
min2 = val;
dp[u] = val;
}
}
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
// n - number of nodes
// m - number of edges
// r[i][0] and r[i][1] - edges of u and v
// l[i] - time taken to cross edge i
// k - number of exit chambers
// p - array of exit chambers
adj.resize(n);
dp.resize(n);
for (int i = 0; i < m; i++){
int u, v, w;
u = r[i][0];
v = r[i][1];
w = l[i];
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
dfs(0, -1);
// for (int i = 0; i < n; i++){
// cout << i << ' ' << dp[i] << '\n';
// }
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |