Submission #1000861

#TimeUsernameProblemLanguageResultExecution timeMemory
1000861TsogRace (IOI11_race)C++14
9 / 100
134 ms262144 KiB
#include "race.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair using namespace std; const int INF = INT_MAX; void dfs(int v, int parent, vector<vector<int>>& dp, const vector<vector<pair<int,int>>>& adj , int K) { for (auto i = 0u; i < adj[v].size(); ++i) { int u = adj[v][i].first; int cos = adj[v][i].second; if (u == parent) { continue; } for (int k = cos; k <= K; ++k) { if (dp[v][k - cos] != INF) { dp[u][k] = min(dp[u][k], dp[v][k - cos] + 1); } } dfs(u, v, dp, adj , K); } } int best_path(int N, int K, int H[][2], int L[]) { vector<vector<pair<int,int>>> adj(N); for (int i = 0; i < N - 1; ++i) { int u = H[i][0], v = H[i][1]; adj[u].push_back(mp(v,L[i])); adj[v].push_back(mp(u,L[i])); } vector<vector<int>> dp(N, vector<int>(200001, INF)); for(int i = 0 ; i < N ; i ++) dp[i][0] = 0; dfs(0, -1, dp, adj , K); int result = INF; for (int v = 0; v < N; ++v) { result = min(result, dp[v][K]); } return (result == INF ? -1 : result); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...