#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, calculated;
void dfs(int v, int p){
if(is[v]){
return;
}
vis[v] = 1;
vector<pair<ll, int>> dist;
map<int, bool> skip;
for(auto k: g[v]){
int u = k.first, e = k.second;
if(u == p) continue;
if(vis[u]){
if(!calculated[u]) skip[u] = 1;
else dist.pb({dp[u] + e, 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 || skip[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);
}
calculated[v] = 1;
}
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:35:26: warning: unused variable 'e' [-Wunused-variable]
35 | int u = k.first, e = k.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31624 KB |
Output is correct |
3 |
Correct |
18 ms |
31664 KB |
Output is correct |
4 |
Correct |
16 ms |
31660 KB |
Output is correct |
5 |
Correct |
17 ms |
31684 KB |
Output is correct |
6 |
Correct |
17 ms |
31692 KB |
Output is correct |
7 |
Correct |
17 ms |
31780 KB |
Output is correct |
8 |
Correct |
18 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31624 KB |
Output is correct |
3 |
Correct |
18 ms |
31664 KB |
Output is correct |
4 |
Correct |
16 ms |
31660 KB |
Output is correct |
5 |
Correct |
17 ms |
31684 KB |
Output is correct |
6 |
Correct |
17 ms |
31692 KB |
Output is correct |
7 |
Correct |
17 ms |
31780 KB |
Output is correct |
8 |
Correct |
18 ms |
31724 KB |
Output is correct |
9 |
Correct |
22 ms |
31956 KB |
Output is correct |
10 |
Incorrect |
16 ms |
31632 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31624 KB |
Output is correct |
3 |
Correct |
18 ms |
31664 KB |
Output is correct |
4 |
Correct |
16 ms |
31660 KB |
Output is correct |
5 |
Correct |
17 ms |
31684 KB |
Output is correct |
6 |
Correct |
17 ms |
31692 KB |
Output is correct |
7 |
Correct |
17 ms |
31780 KB |
Output is correct |
8 |
Correct |
18 ms |
31724 KB |
Output is correct |
9 |
Correct |
22 ms |
31956 KB |
Output is correct |
10 |
Incorrect |
16 ms |
31632 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |