tompotter00 @ 2018-10-16 15:30:13
#include<cstdio>
#include<algorithm>
#include<cstring>
//0-->self
//1-->son
//2-->fa
using std::min;
const int inf=1<<29;
int n,U,V,k,fa[3333],f[3][3333],head[3333],to[3333],next[3333],tot;
void dfs(int x){
// bool fg=1;
int delta=inf;
f[0][x]=1;
f[1][x]=f[2][x]=0;
bool fff=0;
for(int i=head[x];i;i=next[i]){
int y=to[i];
if(fa[x]==y)continue;
fa[y]=x;
dfs(y);
// fg=0;
f[0][x]+=(min(f[0][y],min(f[1][y],f[2][y])));
if(f[1][y]>=f[0][y])fff=1;
delta=min(delta,f[0][y]-f[1][y]);
f[1][x]+=(min(f[0][y],f[1][y]));
f[2][x]+=(min(f[0][y],f[1][y]));
}
if(0==fff){
f[1][x]+=delta;
}
// if(fg){
// f[0][x]=1;
// f[1][x]=inf;
// f[2][x]=0;
// }
}
void add(int x,int y){
to[++tot]=y;
next[tot]=head[x];
head[x]=tot;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d %d",&U,&k);
while(k--){
scanf("%d",&V);add(U,V);add(V,U);
}
}
memset(f,0x3f,sizeof f);
dfs(0);
printf("%d",min(f[0][0],f[1][0]));
}
by 913887524gsd @ 2018-10-18 16:33:45
@tompotter00 大爷您的f[x][2]什么意思……
by tompotter00 @ 2018-10-18 16:49:03
该点的父亲有士兵
by tompotter00 @ 2018-10-18 16:49:27
@913887524gsd 该点的父亲有士兵
by 913887524gsd @ 2018-10-18 16:54:02
@tompotter00
蛤………树形dp还要管父节点的吗……那打扰了。。。弄不来