#Q94. 「一本通 3.5 例 2」最大半连通子图

「一本通 3.5 例 2」最大半连通子图

Description

Original source: ZJOI 2007

A directed graph G=(V,E)G = (V,E) is called Semi-Connected if for every pair of vertices u,vVu,v\in V, there exists either a directed path from uu to vv or a directed path from vv to uu. In other words, for any two vertices uu and vv in the graph, there is at least one directed path connecting them in some direction.

If G=(V,E)G'=(V',E') satisfies that EE’ consists of all edges in EE that are incident to vertices in VV’, then GG’ is called an induced subgraph of GG. If GG’ is an induced subgraph of GG and GG’ is semi-connected, then GG’ is referred to as a semi-connected subgraph of GG. If GG’ is a semi-connected subgraph of GG with the maximum number of vertices, then GG’ is called a maximum semi-connected subgraph of GG.

Given a directed graph GG, determine the number of vertices KK in its maximum semi-connected subgraph and the number of distinct maximum semi-connected subgraphs CC. Since CC might be very large, only output the remainder of CC divided by XX.

Input Format

The first line contains three integers N,M,XN, M, X. Here, NN and MM represent the number of vertices and edges in graph GG, respectively, and XX is the modulus as described above.

The next MM lines each contain two integers aa and bb, indicating a directed edge (a,b)(a, b).

Each vertex in the graph is labeled from 11 to NN. It is guaranteed that no duplicate edges (a,b)(a,b) will appear in the input.

Output Format

The output should consist of two lines. The first line contains the integer KK, and the second line contains CmodXC \bmod X.

Sample 1

6 6 20070603
1 2
2 1
1 3
2 4
5 6
6 4

3
3

Constraints & Hints

For 20%20\% of the data, N18N \le 18; For 60%60\% of the data, N104N \le 10^4; For 100%100\% of the data, 1N1051\le N \le 10^5, 1M1061\le M \le 10^6, and X108X\le 10^8.