# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244177 | bigg | Race (IOI11_race) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
using namespace std;
vector<pair<int,int> > grafo[212345];
int marc[212345];
int dp[212345][112];
int k;
void dfs(int x){
marc[x] = 1;
dp[x][0] = 0;
for(int i = 0; i < grafo[x].size(); i++){
int viz = grafo[x][i].first;
if(marc[viz]) continue;
dfs(viz);
for(int j = grafo[x][i].second; j <= k; j++){
// printf("%d %d %d\n",x, j, dp[x][j] );
dp[x][j] = min(dp[x][j], dp[viz][j - grafo[x][i].second] + 1);
}
}
}
int INF = 1e9;
int n;
int best_path(int N, int K, int H[][2], int L[])
{ n = N;
k = K;
for(int i = 0; i < N - 1; i++){
int u, v, w;
// scanf("%d %d %d", &u, &v, &w);
u = H[i][0];
v = H[i][1];
w = L[i];
grafo[u].push_back(make_pair(v, w));
grafo[v].push_back(make_pair(u, w));
}
for(int i = 0; i < n; i++){
for(int j = 1; j <= 100; j++){
dp[i][j] = INF;
}
}
dfs(0);
int ans = 1e9;
for(int i = 0; i < n; i++){
//printf("%d\n",dp[i][k] );
ans = min(ans, dp[i][k]);
}
if(ans >= INF) ans = -1;
return ans;
}