#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int X = 1e6, MOD = 1e10+7;
int n, m;
vector<ll> dp[2];
vector<pair<int, ll>> g[X];
bitset<X> is, vis;
void dfs(int v, int p){
if(is[v]){
return;
}
vector<ll> dist;
vis[v] = 1;
dp[0][v] = dp[1][v] = MOD;
for(auto k: g[v]){
int u = k.first, e = k.second;
if(u == p) continue;
if(!vis[u])
dfs(u, v);
dist.pb(dp[1][u] + e);
}
sort(dist.begin(), dist.end());
// cout << '\n';
// cout << v << ' ';
// for(int x: dist) cout << x << ' ';
if(dist.empty()) dp[0][v] = MOD;
else dp[0][v] = dist[0];
if(dist.size() == 1) dp[1][v] = MOD;
else dp[1][v] = dist[1];
// cout << dp[0][v] << ' ' << dp[1][v] << ' ' << v << '\n';
}
int travel_plan(int F, int M, int R[][2], int L[], int K, int P[]){
n = F;
m = M;
dp[0].resize(n);
dp[1].resize(n);
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[1][0];
}
Compilation message
crocodile.cpp:6:30: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000007e+10' to '2147483647' [-Woverflow]
6 | const int X = 1e6, MOD = 1e10+7;
| ~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23808 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23952 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23808 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23952 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
9 |
Correct |
13 ms |
24192 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23808 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23892 KB |
Output is correct |
5 |
Correct |
15 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
12 ms |
23952 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
9 |
Correct |
13 ms |
24192 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |