11月10日联考 林檎花火
作者:互联网
性质:删掉任意一个点后,原来能被删的点仍能被删,原来不能被删的点仍不能被删
判断每个点能否被删,并从小到大输出
#include<cstdio> using namespace std; int head[300005],len,a[300005],n,x,y,flag[300005],ans; struct EDGE{ int to,next; }edge[600005]; void add(int x,int y){ ++len; edge[len].to=y; edge[len].next=head[x]; head[x]=len; } void dfs1(int u,int fa){ flag[u]=a[u]; for (register int i=head[u];i;i=edge[i].next){ int v=edge[i].to; if (v!=fa){ dfs1(v,u); flag[u]&=a[v]; } } } int main(){ scanf ("%d",&n); for (register int i=2;i<=n;++i){ scanf ("%d%d",&x,&a[i]); add(x,i);add(i,x); } dfs1(1,0); for (register int i=1;i<=n;++i){ if (flag[i]) ++ans; } printf ("%d\n",ans); for (register int i=1;i<=n;++i){ if (flag[i]) printf ("%d ",i); } printf ("\n"); return 0; }
标签:11,head,被删,int,林檎,len,next,edge,联考 来源: https://www.cnblogs.com/DFTMR/p/11832002.html