#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 1N1\ldots N).

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 (t,x,y)(t,x,y), meaning that at time tt, cow xx shook hooves with cow yy. 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 KK hoofshakes (she may shake hooves with the same cow multiple times). After KK 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 NN cows is patient zero, nor does he know the value of KK! 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 NN (2N1002\le N\le 100) and TT (1T2501\le T\le 250). The next line contains a string of length NN, where each character is 00 or 11, describing the current status of Farmer John’s NN cows: 00 means a healthy cow, and 11 means an infected cow. The next TT lines each contain one record from Farmer John’s interaction list, consisting of three integers tt, xx, and yy, where tt is the positive integer time when an interaction occurred (t250t\le 250), and xx and yy are distinct integers in the range 1N1\ldots N, indicating the two cows that shook hooves at time tt. At most one interaction occurs at any given time.

Output Format

Output one line containing three values xx, yy, and zz, where xx is the number of cows that could be patient zero, yy is the minimum possible value of KK consistent with the data, and zz is the maximum possible value of KK consistent with the data (if the data cannot determine an upper bound for KK, output Infinity for zz). Note that KK may be 00.

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 11. For all K>0K>0, cow 11 infects cow 22 at time 77, and cows 33 and 44 will not be infected.

Translated by ChatGPT 5