A Complex Problem
Time limit3sMemory limit1024 MB
Given subset and proper-subset relations between complexity classes, find the minimum and maximum number of distinct classes that can appear.
- Level
Medium6 of 10
- Topics
- Graph, Union-find, Topological sort
- Solved
- No attempts yet
Problem
There are many problems in computer science, and some are harder than others. Computer scientists group problems into complexity classes and analyze how these classes relate to each other.
A complexity class is simply a set of problems. For example, the complexity class P is the set of decision problems that can be solved by an algorithm whose running time is a polynomial function of the input size. Every problem in P also belongs to NP, the set of decision problems whose "yes" instances can be verified in polynomial time. It is not known whether every problem in NP is also in P, so P and NP could be one class or two distinct classes.
The Halting Problem is in ALL, the set of all decision problems, but it is not in R, the set of decision problems solvable by a Turing machine. So ALL and R are two distinct complexity classes.
Given a series of relations between complexity classes, find the minimum and maximum number of distinct complexity classes.
Input
The first line contains two integers with , separated by a space.
Each of the next lines contains two distinct complexity classes and . Each line means , so every problem in is also in .
Each of the next lines contains two distinct complexity classes and . Each line means , so every problem in is also in , and at least one problem in is not in .
A complexity class is written with one to eight English letters, in uppercase or lowercase. There is at most one relation between any two distinct classes, and the relations do not contradict each other.
Output
Print two integers separated by a space on one line: the minimum and the maximum number of distinct complexity classes that appear in the given relations.