[Solution] Virus Codeforces Solution 2022
There are houses numbered from to on a circle. For each , house and house are neighbours; additionally, house and house are also neighbours.
Initially, of these houses are infected by a deadly virus. Each morning, Cirno can choose a house which is uninfected and protect the house from being infected permanently.
Every day, the following things happen in order:
- Cirno chooses an uninfected house, and protect it permanently.
- All uninfected, unprotected houses which have at least one infected neighbor become infected.
Cirno wants to stop the virus from spreading. Find the minimum number of houses that will be infected in the end, if she optimally choose the houses to protect.
- of
Note that every day Cirno always chooses a house to protect before the virus spreads. Also, a protected house will not be infected forever.
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of test cases follows.
The first line of each test case consists of two positive integers (, ) — the number of houses on the circle, and the number of houses that are initially infected.
The second line of each test case consists of distinct positive integers () — the indices of the houses infected initially.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output an integer on a separate line, which is the minimum number of infected houses in the end.
No comments:
Post a Comment