#P2272. [ZJOI2007] 最大半连通子图

[ZJOI2007] 最大半连通子图

Description

A directed graph G=(V,E)G=\left(V,E\right) is called semi-connected if it satisfies: u,vV\forall u,v\in V, either uvu\to v or vuv\to u, that is, for any two vertices u,vu,v in the graph, there exists a directed path from uu to vv or from vv to uu.

If G=(V,E)G'=\left(V',E'\right) satisfies VVV'\subseteq V and EE' is the set of all edges in EE whose endpoints lie 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 called a semi-connected subgraph of GG. If GG' contains the largest number of vertices among all semi-connected subgraphs of GG, then GG' is called a maximum semi-connected subgraph of GG.

Given a directed graph GG, find KK, the number of vertices in a maximum semi-connected subgraph of GG, and CC, the number of different maximum semi-connected subgraphs. Since CC may be large, output CC modulo XX.

Input Format

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

The next MM lines each contain two positive integers a,ba,b, representing a directed edge (a,b)\left(a,b\right). Each vertex is labeled 1,2,3N1,2,3\dots N. It is guaranteed that the same (a,b)\left(a,b\right) does not appear twice in the input.

Output Format

Output two lines. The first line contains an integer KK. The second line contains an integer CmodXC\bmod X.

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

Hint

For 100%100\% of the testdata, N105N\le 10^5, M106M\le 10^6, X108X\le 10^8.

Translated by ChatGPT 5