A Complex Problem

시간 제한3초메모리 제한1024 MB

요약
여러 복잡도 클래스 사이의 부분집합 및 진부분집합 관계가 주어질 때, 이와 모순되지 않는 서로 다른 클래스 개수의 최솟값과 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
그래프, 유니온 파인드, 위상 정렬, 구현
정답자
아직 제출이 없습니다

문제

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 0≤M,N≤1050 \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 A_iA\_i and B_iB\_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 A_i⊆B_iA\_i \subseteq B\_i, meaning that every problem in A_iA\_i is also in B_iB\_i. Similarly, each of the next NN lines consists of two distinct space-separated complexity classes A_jA\_j and B_jB\_j. Each of these NN lines indicates that A_j⊊B_jA\_j \subsetneq B\_j, meaning that every problem in A_jA\_j is also in B_jB\_j and that at least one problem in B_jB\_j is not in A_jA\_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.

예제4

  1. 예제 1

    입력
    1 0
    P NP
    
    예상 출력
    1 2
    
  2. 예제 2

    입력
    0 1
    R ALL
    
    예상 출력
    2 2
    
  3. 예제 3

    입력
    3 0
    QMIP MIPstar
    MIPstar RE
    RE QMIP
    
    예상 출력
    1 1
    
  4. 예제 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