#P9046. [PA 2021] Pandemia
[PA 2021] Pandemia
Problem Description
A certain country has cities. For all , city and city are connected by a two-way road.
An epidemic breaks out in the country. In each city, either nobody is infected, or everyone is infected. Specifically, a city is infected initially if and only if .
The epidemic will spread. Every day, in the morning, you may vaccinate the residents of one uninfected city. In the afternoon, each infected city spreads to its neighboring cities. If a neighboring city has not been vaccinated, it will immediately become fully infected.
As the city manager, you want to know: under an optimal strategy, what is the minimum number of cities in which everyone becomes infected.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
The first line contains an integer .
The second line contains a string of length .
Output Format
For each test case:
Output one line with an integer, representing the required value.
3
8
00110100
10
1001000010
4
0000
5
7
0
Hint
Sample #1 Explanation
Test case 1: Vaccinate city on the first day, and vaccinate city on the second day.
Test case 2: Vaccinate city on the first day, and vaccinate city on the second day.
Test case 3: There is no epidemic initially, so vaccination is not needed.
Constraints
For of the data, , .
Translated by ChatGPT 5