#P9954. [USACO20OPEN] Cowntact Tracing B
[USACO20OPEN] Cowntact Tracing B
Problem Description
Due to the outbreak of the highly contagious cow disease COWVID-19, Farmer John is very worried about the health of his cows (numbered ).
Recently, Farmer John tested all of his cows and found that some of them tested positive for the disease. Using the barn’s surveillance videos, he was able to review recent interactions between cows. He found that when cows greet each other, they shake hooves; unfortunately, this is an action that can spread the disease from one cow to another. Farmer John compiled a timestamped list, where each record has the form , meaning that at time , cow shook hooves with cow . Farmer John also knows the following information:
(1) There is exactly one cow on his farm that initially carried the disease (we call this cow “patient zero”).
(2) Once a cow becomes infected, she will spread the disease during her next hoofshakes (she may shake hooves with the same cow multiple times). After hoofshakes, she will no longer spread the disease in any future hoofshakes (because she then realizes she can spread the disease, so she will carefully wash her hooves).
(3) Once a cow becomes infected, she will remain infected.
Unfortunately, Farmer John does not know which of his cows is patient zero, nor does he know the value of ! Based on his data, please help him narrow down the possible values of these unknowns. It is guaranteed that at least one scenario is possible.
Input Format
The first line of input contains () and (). The next line contains a string of length , where each character is or , describing the current status of Farmer John’s cows: means a healthy cow, and means an infected cow. The next lines each contain one record from Farmer John’s interaction list, consisting of three integers , , and , where is the positive integer time when an interaction occurred (), and and are distinct integers in the range , indicating the two cows that shook hooves at time . At most one interaction occurs at any given time.
Output Format
Output one line containing three values , , and , where is the number of cows that could be patient zero, is the minimum possible value of consistent with the data, and is the maximum possible value of consistent with the data (if the data cannot determine an upper bound for , output Infinity for ). Note that may be .
4 3
1100
7 1 2
5 2 3
6 2 4
1 1 Infinity
Hint
Sample Explanation 1
The only possible patient zero is cow . For all , cow infects cow at time , and cows and will not be infected.
Translated by ChatGPT 5