N M p1 p2 ... pM x1 y1 x2 y2 ... xM yM

Output Print the number of people covered by at least one insurance.

Sample Input 1 3 2 1 2 2 2 3 1

Sample Output 1 3

Sample Input 2 5 3 1 2 2 2 2 3 1 4 3

Sample Output 2 5

Note In Sample Input 1, person 1 buys the first insurance, covering person 1 and their descendants for 2 generations. Then, person 2 buys the second insurance, covering person 2 and their descendants for 2 generations. Therefore, all 3 people are covered by at least one insurance.

In Sample Input 2, person 1 buys the first insurance, covering person 1 and their descendants for 2 generations. Then, person 2 buys the second insurance, covering person 2 and their descendants for 2 generations. Finally, person 2 buys the third insurance, covering person 4 and their descendants for 3 generations. Therefore, all 5 people are covered by at least one insurance

Problem StatementThere is a family consisting of person 1 person 2 … and person N For i≥2 person is parent is person p i They bought insurance M times For i=12…M person x i bought the i-th insuranc

原文地址: https://www.cveoy.top/t/topic/hSTP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录