#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int X = 1e6, MOD = 1e9+7;
int n, m;
vector<ll> dp(X);
vector<pair<int, ll>> g[X];
bitset<X> is, vis;
void dfs(int v, int p){
if(is[v]){
return;
}
vis[v] = 1;
vector<pair<ll, int>> dist;
for(auto k: g[v]){
int u = k.first, e = k.second;
if(u == p || vis[u]) continue;
dfs(u, v);
}
for(auto k: g[v]){
int u = k.first, e = k.second;
if(u == p) continue;
dist.pb({dp[u] + e, u});
}
sort(dist.begin(), dist.end());
for(auto k: g[v]){
int u = k.first, e = k.second;
if(u == p) continue;
ll d;
if(dist[0].second == u){
if(dist.size() > 1)
d = dist[1].first;
else
d = MOD;
}else{
d = dist[0].first;
}
dp[v] = max(dp[v], d);
}
}
int travel_plan(int F, int M, int R[][2], int L[], int K, int P[]){
n = F;
m = M;
for(int i = 0; i < K; ++i) is[P[i]] = 1;
for(int i = 0; i < m; ++i){
g[R[i][0]].pb({R[i][1], L[i]});
g[R[i][1]].pb({R[i][0], L[i]});
}
dfs(0, 0);
return dp[0];
}
Compilation message
crocodile.cpp: In function 'void dfs(int, int)':
crocodile.cpp:22:26: warning: unused variable 'e' [-Wunused-variable]
22 | int u = k.first, e = k.second;
| ^
crocodile.cpp:33:26: warning: unused variable 'e' [-Wunused-variable]
33 | int u = k.first, e = k.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31552 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
16 ms |
31572 KB |
Output is correct |
4 |
Correct |
15 ms |
31636 KB |
Output is correct |
5 |
Correct |
16 ms |
31700 KB |
Output is correct |
6 |
Correct |
19 ms |
31684 KB |
Output is correct |
7 |
Correct |
19 ms |
31700 KB |
Output is correct |
8 |
Correct |
22 ms |
31700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31552 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
16 ms |
31572 KB |
Output is correct |
4 |
Correct |
15 ms |
31636 KB |
Output is correct |
5 |
Correct |
16 ms |
31700 KB |
Output is correct |
6 |
Correct |
19 ms |
31684 KB |
Output is correct |
7 |
Correct |
19 ms |
31700 KB |
Output is correct |
8 |
Correct |
22 ms |
31700 KB |
Output is correct |
9 |
Incorrect |
18 ms |
31956 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31552 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
16 ms |
31572 KB |
Output is correct |
4 |
Correct |
15 ms |
31636 KB |
Output is correct |
5 |
Correct |
16 ms |
31700 KB |
Output is correct |
6 |
Correct |
19 ms |
31684 KB |
Output is correct |
7 |
Correct |
19 ms |
31700 KB |
Output is correct |
8 |
Correct |
22 ms |
31700 KB |
Output is correct |
9 |
Incorrect |
18 ms |
31956 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |