제출 #422223

#제출 시각아이디문제언어결과실행 시간메모리
422223ScarletS경주 (Race) (IOI11_race)C++17
21 / 100
3088 ms13724 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1<<18, INF = 1e9; int k, x, y, z, ans = INF, dp[1<<20], sub[N], ct, p, h, t; array<int,2> a[N]; array<int,4> d[N]; bool ok; vector<array<int,2>> e[N]; bitset<N> b; void solve(int c) { x=1; a[0]={c,-1}; for (int i=0;i<x;++i) { sub[a[i][0]]=1; for (auto j : e[a[i][0]]) if (j[0]!=a[i][1]&&!b[j[0]]) a[x++]={j[0],a[i][0]}; } for (int i=x-1;i>0;--i) sub[a[i][1]]+=sub[a[i][0]]; t=sub[c]/2; while (1) { ok=1; for (auto i : e[c]) if (i[0]!=p&&!b[i[0]]&&sub[i[0]]>t) { p=c; c=i[0]; ok=0; break; } if (ok) break; } b[c]=1; x=0; for (auto tp : e[c]) if (!b[tp[0]]&&tp[1]<=k) { y=x; z=1; d[0]={tp[0],c,tp[1],1}; for (int i=0;i<z;++i) { ct=d[i][0];p=d[i][1];h=d[i][2];t=d[i][3]; a[x++]={h,t}; ans=min(ans,dp[k-h]+t); for (auto j : e[ct]) if (j[0]!=p&&h+j[1]<=k) d[z++]={j[0],ct,h+j[1],t+1}; } for (int j=y;j<x;++j) dp[a[j][0]]=min(dp[a[j][0]],a[j][1]); } for (int i=0;i<x;++i) dp[a[i][0]]=INF; for (auto i : e[c]) if (!b[i[0]]) solve(i[0]); } int best_path(int n, int K, int h[][2], int l[]) { k=K; for (int i=0;i<n-1;++i) { e[h[i][0]].push_back({h[i][1],l[i]}); e[h[i][1]].push_back({h[i][0],l[i]}); } for (int i=1;i<=k;++i) dp[i]=INF; solve(0); if (ans==INF) return -1; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...