#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ll long long
#define ss second
const int M=2e5+5;
ll ans=INT_MAX;
vector<pair<ll,ll>>v[M];
bool vis[M];
ll Z;
vector<ll> fun(ll a){
vis[a]=1;
vector<ll>dp(150);
for(ll i=0;i<=Z;i++)dp[i]=INT_MAX;
dp[0]=0;
for(auto p:v[a]){
ll b=p.ff;
ll c=p.ss;
if(vis[b]==0){
vector<ll>vc=fun(b);
for(ll i=0;i<=Z;i++){
ans=min(ans,dp[i]+vc[Z-i]+2);
}
for(int i=0;i<=Z-c;i++){
dp[i+c]=min(dp[i+c],vc[i]+1);
}
}
}
ans=min(ans,dp[Z]);
return dp;
}
int best_path(int N, int K, int H[][2], int L[]){
Z=K;
for(int i=0;i<N-1;i++){
int a=H[i][0];
int b=H[i][1];
int c=L[i];
v[a].pb({b,c});
v[b].pb({a,c});
}
fun(0);
if(ans==INT_MAX)return -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
1 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
9096 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
1 ms |
9052 KB |
Output is correct |
10 |
Correct |
1 ms |
9304 KB |
Output is correct |
11 |
Correct |
1 ms |
9052 KB |
Output is correct |
12 |
Correct |
1 ms |
9052 KB |
Output is correct |
13 |
Correct |
1 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
1 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
9052 KB |
Output is correct |
18 |
Correct |
1 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
1 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
9096 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
1 ms |
9052 KB |
Output is correct |
10 |
Correct |
1 ms |
9304 KB |
Output is correct |
11 |
Correct |
1 ms |
9052 KB |
Output is correct |
12 |
Correct |
1 ms |
9052 KB |
Output is correct |
13 |
Correct |
1 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
1 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
9052 KB |
Output is correct |
18 |
Correct |
1 ms |
9052 KB |
Output is correct |
19 |
Incorrect |
1 ms |
8796 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
1 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
9096 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
1 ms |
9052 KB |
Output is correct |
10 |
Correct |
1 ms |
9304 KB |
Output is correct |
11 |
Correct |
1 ms |
9052 KB |
Output is correct |
12 |
Correct |
1 ms |
9052 KB |
Output is correct |
13 |
Correct |
1 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
1 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
9052 KB |
Output is correct |
18 |
Correct |
1 ms |
9052 KB |
Output is correct |
19 |
Incorrect |
53 ms |
16412 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
1 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
9096 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
1 ms |
9052 KB |
Output is correct |
10 |
Correct |
1 ms |
9304 KB |
Output is correct |
11 |
Correct |
1 ms |
9052 KB |
Output is correct |
12 |
Correct |
1 ms |
9052 KB |
Output is correct |
13 |
Correct |
1 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
9052 KB |
Output is correct |
15 |
Correct |
2 ms |
9052 KB |
Output is correct |
16 |
Correct |
1 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
9052 KB |
Output is correct |
18 |
Correct |
1 ms |
9052 KB |
Output is correct |
19 |
Incorrect |
1 ms |
8796 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |