PivotOJ

A Complex Problem

시간 제한: 3000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2023-2024BOJ 30540

문제

There are many problems in the field of computer science, and some are harder than others. Computer scientists have accordingly categorized problems using complexity classes, and like to analyze these classes to see how they interact with each other.

A complexity class is a simply a set of problems; for example, the complexity class P is the set of decision problems which are solvable with an algorithm whose runtime scales as a polynomial function of the input size. We know some results about the relations between complexity classes: for example, every problem in the complexity class P also belongs to the complexity class NP of decision problems for which "yes"-instances can be verified in polynomial time. However, we don't know if every problem in NP is also in P (and we won't ask you to figure this out for today). Therefore, P and NP could be either one or two distinct complexity classes. On the other hand, we know that the Halting Problem is in ALL (the set of all decision problems) but not in R (the set of decision problems solvable by a Turing machine). Therefore, ALL and R are two distinct complexity classes.

Given a series of relations between complexity classes, can you find the minimum and maximum number of distinct complexity classes? Two complexity classes are distinct if and only if there is some problem that exists in one class but not in the other.

입력

Input begins with two space-separated integers 0M,N1050 \leq M, N \leq 10^5 such that M+N>0M + N > 0. Each of the next MM lines consists of two distinct space-separated complexity classes AiA_i and BiB_i, where a complexity class is a set of problems, denoted by one to eight uppercase or lowercase English letters. Each of these MM lines indicates that AiBiA_i \subseteq B_i, meaning that every problem in AiA_i is also in BiB_i. Similarly, each of the next NN lines consists of two distinct space-separated complexity classes AjA_j and BjB_j. Each of these NN lines indicates that AjBjA_j \subsetneq B_j, meaning that every problem in AjA_j is also in BjB_j and that at least one problem in BjB_j is not in AjA_j.

There is at most one relation between any two distinct complexity classes specified in the input, and the relations between complexity classes will not imply any logical contradiction.

출력

Output two space-separated integers on a single line: the minimum and maximum number of distinct complexity classes among the specified complexity classes given in the relations in the input.

예제

예제 1

입력
1 0
P NP
출력
1 2

예제 2

입력
0 1
R ALL
출력
2 2

예제 3

입력
3 0
QMIP MIPstar
MIPstar RE
RE QMIP
출력
1 1

예제 4

입력
11 8
NC P
P BPP
P coNP
P NP
BPP BQP
coNP PSPACE
BQP PSPACE
NP PSPACE
PSPACE EXPTIME
EXPTIME NEXPTIME
NEXPTIME EXPSPACE
REG CFL
CFL NC
CFL CSL
NC PSPACE
CSL PSPACE
EXPSPACE R
R RE
RE ALL
출력
7 16
코드를 제출하려면 로그인하세요.