| 记录编号 | 
        40729 | 
        评测结果 | 
        AAAAAAATTT | 
    
    
        | 题目名称 | 
        936.[河南省队2012] 座位问题 | 
        最终得分 | 
        70 | 
            
    
    
        | 用户昵称 | 
         苏轼 | 
        是否通过 | 
        未通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        0.456 s  | 
    
    
        | 提交时间 | 
        2012-07-18 20:42:51 | 
        内存使用 | 
        2.32 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
using namespace std;
int number;
struct hehe
{
	int father;
	bool use;
}b[100001];
vector<int>a[100001];
bool used[100001]={0};
void dfs(int x);
int main()
{
	freopen ("seat.in","r",stdin);
	freopen ("seat.out","w",stdout);
	cin>>number;
	for (int i=1;i<number;i++)
	{
		b[i].use=0;
		int xx,yy;
		cin>>xx>>yy;
		a[xx].push_back(yy);
		a[yy].push_back(xx);
	}
	b[1].father=-1;
	b[1].use=1;
	dfs(1);
	for (int i=0;i<number;i++)
	{
		int c,ans=0;
		cin>>c;
		used[c]=1;
		while (b[c].father!=-1)
		{
			if (used[b[c].father])
				ans++;
			c=b[c].father;
		}
		cout<<ans<<endl;
	}
	return 0;
}
void dfs(int x)
{
	for (int i=0;i<a[x].size();i++)
	{
		if (b[a[x][i]].use==1)
			continue;
		b[a[x][i]].father=x;
		b[a[x][i]].use=1;
		int d;
		d=a[x][i];
		dfs(d);
	}
}