#P16041. [ICPC 2022 NAC] Contact Tracing
[ICPC 2022 NAC] Contact Tracing
题目描述
A novel infectious disease has started spreading through the population. You are tasked with figuring out who might be infected in order to get them to quarantine. The behavior of the disease among members of the population is as follows:
- When a person comes into contact with someone who is infectious, they may (but do not always) catch the disease. If they catch the disease, they are not infectious for the rest of that day, so they will not spread it to other people they come into contact with that day.
- When a person catches the disease, they are infectious starting the day after they caught the disease.
- Starting two days after they caught the disease, they are symptomatic; as a result, they will quarantine themselves and not come into contact with any other people from then on.
You know that on day , a single Patient Zero (of unknown identity) caught the disease. On day , they were infectious and potentially came into contact with people, potentially infecting those people. On day , Patient Zero became symptomatic and therefore stopped coming into contact with other people, but any people who were infected on day could potentially spread the disease to the people they come into contact with.
Today is day , and it is the end of the day. You have access to a list of all pairs of people who came into contact with each other on each day, including today. If you can identify all people who could be infectious but not symptomatic tomorrow (because they caught the disease today) and tell them to quarantine, you can halt the outbreak, because all people who are symptomatic tomorrow will quarantine themselves anyway. What is the minimum number of people you need to tell to quarantine to be sure that you halt the outbreak?
输入格式
The first line of input contains three integers (), (), and (), where is the number of people, is the number of days since Patient Zero became infected, and is the number of contacts that occurred between people.
Each of the next lines contains three space-separated integers , (), and (), denoting that people and came into contact with each other on day . All of these lines will be distinct. There will be at least one person with no contacts after day .
输出格式
Output a line with a single integer denoting the minimum number of people you must tell to quarantine beginning on day . Then, output lines listing the people who must quarantine, one per line, in ascending order.
4 2 4
1 4 1
2 3 2
2 4 1
3 4 1
2
2
3
提示
Explanation of Sample Input 1
In Sample Input 1, Patient Zero could be person or person . Persons and can be eliminated, because they had contact on day , when Patient Zero would be symptomatic and quarantined.
Suppose person is Patient Zero. Person may have infected person on day . Person is symptomatic on day , so they begin quarantining. Therefore, there is no chain of contact from person (Patient Zero) to persons or , so person and person are safe and do not need to be quarantined. If person infected person on day , then person will be symptomatic tomorrow (day ), so there is no need to contact them because they will isolate on their own. Therefore if Patient Zero is person , no one needs to be notified.
Now suppose person is Patient Zero. Person may have infected person on day ; using the same logic as above, there is no need to notify person or person to quarantine on day . This leaves persons and , which requires us to consider multiple infection patterns.
If person infected both persons and on day , then both of them will be symptomatic and self-quarantine starting on day , so we do not need to notify them.
Suppose instead person infected person but NOT person on day . (Remember that transmission is not guaranteed.) In this case, person could go on to infect person on day , and person would not yet be symptomatic on day , so we would need to notify person to quarantine.
Similarly, if person infected person but NOT person on day , we would need to notify person to quarantine.
Therefore to be sure we can halt the outbreak, we need to notify both person and person to quarantine. This is guaranteed to stop the outbreak, whether person or person is Patient Zero.