Submission #412491

#TimeUsernameProblemLanguageResultExecution timeMemory
412491jeqchoRace (IOI11_race)C++17
9 / 100
344 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second int const n=2e5+3; int const k_=1e2+3; pair<int,pii> dp[n][k_]; vpi adj[n]; int const INF=1e9; int mn=INF; void dfs(int now, int par, int k) { F0R(i,k+1) { dp[now][i]={INF,pii{-1,-1}}; } dp[now][0].fi=0; dp[now][0].se.fi=now; trav(chi,adj[now]) { if(chi.fi==par)continue; dfs(chi.fi,now,k); F0R(i,k+1) { if(i-chi.se<0)continue; if(dp[chi.fi][i-chi.se].fi+1 == dp[now][i].fi) { dp[now][i].se.se=chi.fi; } else if(dp[chi.fi][i-chi.se].fi+1 < dp[now][i].fi) { dp[now][i] = {dp[chi.fi][i-chi.se].fi+1, pii{chi.fi,-1}}; } } } F0R(i,k+1) { if(dp[now][i].se.fi==-1)continue; if(dp[now][k-i].se.fi==-1)continue; if(dp[now][i].se.fi==dp[now][k-i].se.fi) { if(dp[now][i].se.se==-1&&dp[now][k-i].se.se==-1)continue; } mn=min(mn,dp[now][i].fi+dp[now][k-i].fi); } } int best_path(int N, int K, int H[][2], int L[]){ F0R(i,N-1) { int u = H[i][0]; int v = H[i][1]; adj[u].pb({v,L[i]}); adj[v].pb({u,L[i]}); } dfs(0,-1,K); if(mn>=INF)return -1; return mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...