#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>
#define MAX_N 50000
#define MAX_M 10000000
static int N, M;
static int R[MAX_M][2];
static int L[MAX_M];
static int K;
static int P[MAX_N];
static int solution;
using namespace std;
inline
void my_assert(int e) {if (!e) abort();}
vector<vector<pair<int,int>>> adj;
vector<int> dp;
void dfs(int u, int p){
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;
if (w < min1){
min2 = min1;
dp[u] = dp[v] + w;
min1 = w;
}
else if (min1 < w && w < min2){
min2 = w;
dp[u] = dp[v] + w;
}
}
}
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);
return dp[0];
}
Compilation message
crocodile.cpp:27:12: warning: 'solution' defined but not used [-Wunused-variable]
27 | static int solution;
| ^~~~~~~~
crocodile.cpp:26:12: warning: 'P' defined but not used [-Wunused-variable]
26 | static int P[MAX_N];
| ^
crocodile.cpp:25:12: warning: 'K' defined but not used [-Wunused-variable]
25 | static int K;
| ^
crocodile.cpp:24:12: warning: 'L' defined but not used [-Wunused-variable]
24 | static int L[MAX_M];
| ^
crocodile.cpp:23:12: warning: 'R' defined but not used [-Wunused-variable]
23 | static int R[MAX_M][2];
| ^
crocodile.cpp:22:15: warning: 'M' defined but not used [-Wunused-variable]
22 | static int N, M;
| ^
crocodile.cpp:22:12: warning: 'N' defined but not used [-Wunused-variable]
22 | static int N, M;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |