#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define s second
#define pb push_back
#define f first
const int nn = 100005;
vector <pair<int,int> > v[nn];
int dp[nn];
// int R[nn][4],L[nn],P[nn];
void dfs(int x,int par){
int mn1 = 1e9,mn2 = 1e9;
for (auto [to,w]: v[x]){
if (to == par) continue;
dfs(to,x);
int vl = dp[to] + w;
if (vl < mn1) mn2 = mn1,mn1 = vl;
else if (vl < mn2) mn2 = vl;
}
if (v[x].size() == 1) dp[x] = 0;
else dp[x] = mn2;
}
/*int main (){
int N,M,K;
cin>>N>>M>>K;
*/
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for (int i = 0; i < M; i++){
// cin>>R[i][0]>>R[i][1]>>L[i];
v[R[i][0]].pb({R[i][1],L[i]});
v[R[i][1]].pb({R[i][0],L[i]});
}
// for (int i = 0; i < K; i++)
// cin>>P[i];
dfs(0,0);
return dp[0];
// cout<<dp[0];
}
Compilation message
crocodile.cpp: In function 'void dfs(int, int)':
crocodile.cpp:16:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for (auto [to,w]: v[x]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |