Submission #1084280

#TimeUsernameProblemLanguageResultExecution timeMemory
1084280EkinOnalRace (IOI11_race)C++17
0 / 100
5 ms10588 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #define MAX 200000 #define pb push_back #define mp make_pair #define f first #define s second #define vi vector<int> #define pii pair<int,int> #define si set<int> #define vpii vector<pair<int,int>> const int mod = 1e9+7; const int INF = 1e9; int n,k,cev; vpii adj[MAX]; vi dead(MAX),sz(MAX),mpp(1e6+5); void dfs(int node,int par){ sz[node]=1; for(auto u : adj[node]){ if(dead[u.f] || u.f==par) continue; sz[node]+=sz[u.f]; } } int findc(int node,int par,int val){ for(auto u : adj[node]){ if(dead[u.f] || u.f==par) continue; if(sz[u.f]>=val/2) return findc(u.f,node,val); // val olmalidir } return node; } void check(int node,int par,int len,int sayi){ if(len>k) return; if(mpp[k-len]!=INF) cev=min(cev,mpp[k-len]+sayi); for(auto u : adj[node]){ if(dead[u.f] || u.f==par) continue; check(u.f,node,len+u.s,sayi+1); } } void build(int node,int par,int len,int sayi){ if(len>k) return; mpp[len]=min(mpp[len],sayi); for(auto u : adj[node]){ if(dead[u.f] || u.f==par) continue; check(u.f,node,len+u.s,sayi+1); } } void sifirla(int node,int par,int der){ if(der>k) return; mpp[der]=INF; for(auto u : adj[node]){ if(dead[u.f] || u.f==par) continue; sifirla(u.f,node,der+u.s); } } void solve(int node){ dfs(node,node); int x = findc(node,node,sz[node]); dead[x]=true; mpp[0]=0; for(auto u : adj[x]){ if(dead[u.f]) continue; check(u.f,x,u.s,1); build(u.f,x,u.s,1); } for(auto u : adj[x]){ if(dead[u.f]) continue; sifirla(u.f,x,u.s); } for(auto u : adj[x]){ if(dead[u.f]) continue; solve(u.f); } } int best_path(int N, int K, int H[][2], int L[]) { n=N,k=K; for(int i=0;i<n-1;i++){ adj[H[i][0]].pb({H[i][1],L[i]}); adj[H[i][1]].pb({H[i][0],L[i]}); } fill(mpp.begin(),mpp.end(),INF); cev=n+2; solve(0); if(cev==n+2) cev=-1; return cev; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...