eolymp
bolt
Try our new interface for solving problems
Problems

Sociology

Sociology

Vasya works for the RISK (Research Institute of Sociological tasKs). He is studying relationships between software engineers working freelance and their managers. Vasya considers several jobs assigned to programmers. Each job is to be done by one engineer and is to be managed by one manager. Vasya calls a subset \textbf{A} of managers excessive if the subset of engineers having common jobs with at least one of managers from \textbf{A} has lesser cardinality than \textbf{|A|}. His hypothesis is that a system having no excessive subsets of managers is more stable and produces less pressure to the workers. Your task is to find an excessive subset or say that it is impossible. \InputFile Input consists of no more than \textbf{10} test cases. The first line of each test case contains two integers \textbf{N_e} and \textbf{N_m} - the number of engineers and managers, respectively (\textbf{1} ≤ \textbf{N_e}, \textbf{N_m} ≤ \textbf{10^4}). The next line contains a single integer \textbf{N_j} - the number of jobs (\textbf{1} ≤ \textbf{N_j} ≤ \textbf{10^5}). Then \textbf{N_j} lines follow, each containing two integers \textbf{e_i} and \textbf{m_i} - numbers of engineer and manager assigned to job number \textbf{i}. \OutputFile For each test case, output either an excessive subset of managers or a message that it does not exist. Adhere to the sample output below as close as possible.
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
3 3
6
1 2
1 3
2 3
2 1
3 1
3 2
2 3
2
1 3
2 2
1 3
3
1 1
1 2
1 3
Output example #1
Case #1: There is no excessive subset of managers.
Case #2: Manager 1 forms an excessive subset.
Case #3: Managers 1 and 2 form an excessive subset.
Author Vitaly Valtman, Yury Petrov