#abc309e. E - Family and Insurance
E - Family and Insurance
Score : points
问题描述
存在一个家庭,成员包括第 人、第 人,……,直至第 人。对于任意 ,第 人的父母是第 人。
他们购买了保险共 次。对于 ,第 人购买了第 次保险,该保险覆盖其本人及其下 代的后代。
请问至少被一份保险覆盖的人数有多少?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a family consisting of person , person , , and person . For , person 's parent is person .
They bought insurance times. For , person bought the -th insurance, which covers that person and their descendants in the next generations.
How many people are covered by at least one insurance?
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
7 3
1 2 1 3 3 3
1 1
1 2
4 3
Sample Output 1
4
The -st insurance covers people , , and , because person 's -st generation descendants are people and .
The -nd insurance covers people , , , and , because person 's -st generation descendants are people and , and person 's -nd generation descendant is person .
The -rd insurance covers person , because person has no -st, -nd, or -rd descendants.
Therefore, four people, people , , , and , are covered by at least one insurance.
Sample Input 2
10 10
1 1 3 1 2 3 3 5 7
2 1
5 1
4 3
6 3
2 1
7 3
9 2
1 2
6 2
8 1
Sample Output 2
10
update @ 2024/3/10 08:46:42