#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const ll INF = numeric_limits<ll>::max();
vector<pii> adj[MAXN+10];
ll dist[MAXN+10], dp[MAXN+10];
void dfs(int now, int par, ll dis)
{
dist[now]=dis;
if(adj[now].size()==1) { dp[now]=dis; return; }
pll ret={INF, INF};
for(pii nxt : adj[now])
{
if(nxt.first==par) continue;
dfs(nxt.first, now, dis+nxt.second);
if(dp[nxt.first]<=ret.first) ret.second=ret.first, ret.first=dp[nxt.first];
else if(dp[nxt.first]<=ret.second) ret.second=dp[nxt.first];
}
dp[now]=ret.second;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
int i, j;
for(i=0; i<M; i++)
{
int 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, 0);
//for(i=0; i<N; i++) printf("%lld %lld\n", dist[i], dp[i]);
return dp[0];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:32:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Runtime error |
279 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Runtime error |
279 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |