Infection
Time limit1sMemory limit1024 MB
Given timed contacts that spread infection with probability 1/2, find each employee's infection probability, given that employee k ends up infected.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation, Probability
- Solved
- No attempts yet
Problem
An emergency happened in one secret organization. In the middle of the working day, one of the employees was hospitalized with symptoms of an extremely dangerous colonavirus infection. Management now wants to know which employees can still be infected, even though their symptoms have not yet appeared.
The organization has employees, numbered with integers from 1 to . From CCTV recordings, management established when each pair of employees contacted each other. Management also made the following assumptions.
- At the beginning of the working day, exactly one employee was infected, and each initial state has probability .
- If two employees come into contact, and one is infected and the other is not, the healthy employee becomes infected with probability . If both are healthy, or both are infected, nothing happens.
- An infected employee cannot recover. He remains infected until the end.
- It is known that employee was eventually infected.
The contacts are given in chronological order. Determine the probability that each employee is infected under the assumptions above.
Input
The first line contains three integers , and , the number of employees, the number of the infected employee, and the number of contacts (, , ).
Each of the following lines contains two integers and , the indexes of the employees who took part in the -th contact (, ).
All contacts are given in chronological order.
Output
Print lines. On the -th line, print the probability that employee is infected as an irreducible fraction .