#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);
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 || vis[u]) 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:29:26: warning: unused variable 'e' [-Wunused-variable]
29 | int u = k.first, e = k.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |