Submission #412497

#TimeUsernameProblemLanguageResultExecution timeMemory
412497jeqchoRace (IOI11_race)C++17
9 / 100
380 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 struct triple{ int a,b,c; }; int const n=2e5; int const k_=1e2+1; triple dp[n][k_]; vpi adj[n]; int const INF=1e9; int mn=INF; int k; void dfs(int now, int par) { F0R(i,k+1) { dp[now][i]={INF,-1,-1}; } dp[now][0].a=0; dp[now][0].b=now; trav(chi,adj[now]) { if(chi.fi==par)continue; dfs(chi.fi,now); F0R(i,k+1) { if(i-chi.se<0)continue; if(dp[chi.fi][i-chi.se].a+1 == dp[now][i].a) { dp[now][i].c=chi.fi; } else if(dp[chi.fi][i-chi.se].a+1 < dp[now][i].a) { dp[now][i] = {dp[chi.fi][i-chi.se].a+1, chi.fi,-1}; } } } F0R(i,k+1) { if(dp[now][i].a==-1)continue; if(dp[now][k-i].a==-1)continue; if(dp[now][i].b==dp[now][k-i].b) { if(dp[now][i].c==-1&&dp[now][k-i].c==-1)continue; } mn=min(mn,dp[now][i].a+dp[now][k-i].a); } } int best_path(int N, int K, int H[][2], int L[]){ k=K; 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); 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...