Mosher @ 2019-05-10 17:21:55
#include<bits/stdc++.h>
using namespace std;
const int maxn=3001;
int f[maxn],point[maxn],id[maxn],dis[maxn],n,ans,son,fa;
bool cmp(int x,int y){
if(dis[x]>dis[y]) return 1;
else if(dis[x]==dis[y]) return x>y;
else return 0;
}
int main(){
freopen("in.txt","r",stdin);
scanf("%d",&n);point[0]=maxn;
for(int i=1,doit,num;i<=n;++i){
scanf("%d%d",&doit,&num);doit++;
point[doit]=maxn;
for(int j=1,v;j<=num;++j){
scanf("%d",&v);v++;
f[v]=doit;dis[v]=dis[f[v]]+1;id[v]=v;
}
}
sort(id+1,id+1+n,cmp);
for(int i=1;i<=n;++i){
son=id[i];fa=f[son];
point[son]=min(point[son],point[fa]+1);
if(point[son]>1){
point[fa]=0;ans++;
point[f[fa]]=min(point[f[fa]],1);
}
}
printf("%d",ans);
return 0;
}
by 我不认识你 @ 2019-05-10 17:59:59
@木隐兮 不是dp吗
by zzy2333 @ 2019-05-10 18:27:44
这题是dp
by Mosher @ 2019-05-11 08:20:36