This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#define INF 0x7ffffff
using namespace std;
vector <int> X[13000];
vector <int> LEV[3001];
int D[10001], Cnt[13000];
void DFS(int now, int lev)
{
int i, j=X[now].size();
LEV[lev].push_back(now);
for(i=0 ; i<j ; i++)
{
DFS(X[now][i],lev+1);
Cnt[now]+=Cnt[X[now][i]];
}
}
int DeletePlan( int N, int M, int K, int *A, int *B)
{
int i, j, k, l;
for(i=0 ; i<N ; i++)
{
X[A[i]+N].push_back(i);
Cnt[i]=1;
D[i+1]=INF;
}
for(i=1 ; i<M ; i++)
X[B[i]+N].push_back(i+N);
DFS(N,0);
for(i=0 ; i<=M ; i++)
{
k=LEV[i].size();
for(j=0 ; j<k ; j++)
{
for(l=N ; l>=Cnt[LEV[i][j]] ; l--)
if(D[l]>D[l-Cnt[LEV[i][j]]]+1)
D[l]=D[l-Cnt[LEV[i][j]]]+1;
}
}
return D[K];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |