Connecting Computers

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

요약
각 간선에 k가지 케이블 종류 중 하나가 붙은 그래프에서 연결을 유지하는 최소 종류 수와 그러한 부분집합의 개수를 구한다.
난이도

어려움10점 중 9점

유형
그래프, 유니온 파인드, 비트 연산, 수학
정답자
아직 제출이 없습니다

문제

The tech team is gearing up for the PacNW Regional! There are nn computers that need to be connected together for the contest, isolated from the outside internet. There are mm bidirectional connections between computers, each connection requiring one of kk different types of cable (for example, CAT5, RS232, MIDI, etc.) Using all the possible cable types, every computer is reachable from every other computer by following some set of cables. In addition, each pair of computers participates in at most one connection. Finally, to minimize leakage, no two distinct simple cycles of connected computers can have more than one computer in common (a simple cycle is a cycle where each computer can appear at most once, and two cycles are distinct if there is at least one connection present in one but not the other).

The tech team needs to make sure that every computer can communicate with every other computer, but doesn't want to use all the cable types if they don't have to. Can you help them figure out the answers to two questions: what is the minimum number of cable types they need to connect all of the computers, and how many subsets of cable types would allow every computer to communicate with every other computer?

입력

The first line contains three integers nn, mm, and kk (1≤n≤2⋅1051\le n\le 2\cdot 10^5, n−1≤m≤3⋅105n - 1\le m\le 3\cdot 10^5, 1≤k≤241\le k\le 24) --- the number of computers, the number of connections, and the number of cable types respectively.

The next line contains kk strings: the ithi^{\text{th}} string is the name of the ithi^{\text{th}} cable type. Each cable name is made up of between 11 and 1010 alphanumeric characters. It is guaranteed that the cable names are distinct.

The next mm lines describe the connections between the computers. The ithi^{\text{th}} line contains two integers xx and yy (1≤x<y≤n1\le x < y\le n) and a string ss (guaranteed to be one of the cable types).

출력

Output two lines, each containing a single integer. The first line should contain the minimum number of cable types the tech team needs connect all the computers. The second line should contain the number of subsets of cable types such that only installing those types would connect all of the computers.

예제1

  1. 예제 1

    입력
    6 7 4
    CAT5 RS232 MIDI USBC
    1 2 CAT5
    2 3 MIDI
    3 4 MIDI
    2 4 CAT5
    4 5 MIDI
    5 6 MIDI
    4 6 RS232
    
    예상 출력
    2
    4