标签:efi \n clu bit node max its mes str
#include<bits/stdc++.h> #define maxn 100000 using namespace std; int k=0,head[maxn]; int f[maxn][2]; int ans=0; struct node{ int v,nxt; }e[maxn<<1]; void adde(int u,int v){ e[k].v=v; e[k].nxt=head[u]; head[u]=k++; } void dp(int u,int fa){ f[u][0]=0;f[u][1]=1; for(int i=head[u];~i;i=e[i].nxt){ int v=e[i].v; if (v==fa) continue; dp(v,u); f[u][0]+=f[v][1]; f[u][1]+=min(f[v][0],f[v][1]); } } void init(){ freopen("soldier.in.txt","r",stdin); //freopen("solider.txt","w",stdout); } void readdata(){ int n,x,y,m; while(scanf("%d",&n)!=EOF){ memset(head,-1,sizeof(head)); for(int i=1;i<=n;i++){ scanf("%d:(%d)",&x,&m); for(int j=1;j<=m;j++){ scanf("%d",&y); adde(x,y); adde(y,x); } } dp(0,-1); printf("%d\n",min(f[0][1],f[0][0])); } } int main(){ //init(); readdata(); return 0; }
标签:efi \n clu bit node max its mes str
原文地址:https://www.cnblogs.com/quietus/p/10299998.html