#graph103. 最大半连通子图

最大半连通子图

Largest Semi-Connected Subgraph

Problem Source

ZJOI2007

Problem Description

A directed graph G=(V,E)G = (V, E) is called semi-connected if: for all u,v∈Vu, v \in V, either u→vu \to v or v→uv \to u, i.e. for any two vertices u,vu, v in the graph there is a directed path from uu to vv or from vv to uu.

If G′=(V′,E′)G' = (V', E') satisfies V′⊂VV' \subset V and E′E' consists of all edges in EE related to V′V', then G′G' is called an induced subgraph of GG. If G′G' is an induced subgraph of GG and is semi-connected, then G′G' is a semi-connected subgraph of GG.

If G′G' is the semi-connected subgraph of GG containing the most vertices, then G′G' is the largest semi-connected subgraph. Given a directed graph GG, find KK, the number of vertices in the largest semi-connected subgraph of GG, and CC, the number of different largest semi-connected subgraphs. Since CC may be large, only output C mod XC \bmod X.

Input Format

The first line contains three integers N,M,XN, M, X. N,MN, M are the number of vertices and edges of GG; the meaning of XX is as above.

The next MM lines each contain two positive integers a,b (1≤a,b≤N)a, b\ (1 \le a, b \le N), representing a directed edge (a,b)(a, b).

There are no multiple edges in the input. N≤105, M≤106, X≤108N \le 10^5,\ M \le 10^6,\ X \le 10^8.

Output Format

Two lines in total. The first line contains one integer KK; the second line contains C mod XC \bmod X.

Sample Input

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

Sample Output

3
3