2762Full Contained

2762   Full Contained

题目描述

 There is a tree, it's root is point 1.Then Job adds some edges, so for each subtree, he want to know the number of new edges which are full contained by this subtree. The means of full contained is that the edge's two endpoints u and v are both in the subtree. 

输入格式:

  Input contains multiple test cases. Each test case starts with two numbers n(the number of points) and m(the number of edges that are added) (2<=n<=10^6,1<=m<=10^5).

  The next line contains n-1 integer,a[1],a[2]...a[n-1]. a[i] means there is an edge between i+1 and a[i] (1 <= a[i] <= i)

  The next m lines contain two integer numbers each which means the endpoint of edge that is added. (1 <= a, b <= n && a != b)

输出格式:

For each text case, output n numbers, the i'th integer is the number of full contained edges of subtree with root i

输入样例 复制
2 1
1
1 2
6 4
1 1 2 2 3
4 5
2 4
3 5
3 6
输出样例 复制
1 0
4 2 1 0 0 0

说明

1
1
通过提交
时空限制3000ms/128mb
题目来源
评测方式在线评测
题目类型
难        度