| 记录编号 | 
        600492 | 
        评测结果 | 
        WWWWWWWWWW | 
    
    
        | 题目名称 | 
        4140.终末鸟 | 
        最终得分 | 
        0 | 
            
    
    
        | 用户昵称 | 
         123 | 
        是否通过 | 
        未通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        7.841 s  | 
    
    
        | 提交时间 | 
        2025-05-05 15:05:35 | 
        内存使用 | 
        47.52 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		#include <bits/stdc++.h>
using namespace std;
const int N=1e7+10;
int n,q,idx[N],nxt[N],head[N],tot=0,f[N],ret=0,size[N],a[N]; 
void add(int x,int y)
{
	idx[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
void dfs(int now,int fa)
{
	f[now]=fa;
	for (int i=head[now];i;i=nxt[i])
	{
		int y=idx[i];
		if (a[y]==1) {size[now]++;}
		if (y!=fa) dfs(y,now);
	} 
	if (a[fa]==0 && a[now]==1)
	{
		ret++;
	 } 
}
int main() {
	freopen("birds.in","r",stdin);
	freopen("birds.out","w",stdout); 
	cin>>n;
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	dfs(1,0);
	cin>>q; 
	cout<<ret<<endl; 
	while (q--)
	{
		int x;
		scanf("%d",&x);
		if (a[x]==0)
		{
			if (a[f[x]]==1) {ret--;}
			ret-=size[x];
			size[f[x]]--;
			ret++; 
		}
		else
		{
			if (x!=1 && a[f[x]]==1) {ret++;}
			ret+=size[x];
			size[f[x]]++;
			ret--; 
		}
		a[x]=1-a[x]; 
		printf("%d\n",ret);
	}
}