#abc226e. E - Just one
E - Just one
Score : points
问题描述
给定一个包含 个顶点和 条边的无向图。顶点依次命名为 Vertex , Vertex , , Vertex ,边依次命名为 Edge , Edge , , Edge 。其中第 条边()连接顶点 Vertex 和 Vertex 。本题保证该图是简单图:即不存在自环和平行边。
对于图中的每一条边,有 种定向方法。我们希望每个顶点恰有一条边从该顶点指向另一个顶点。请问有多少种方式可以按照这种方式定向所有边?由于答案可能非常大,请输出模 后的结果。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Given is an undirected graph with vertices and edges. The vertices are called Vertex , Vertex , , Vertex , and the edges are called Edge , Edge , , Edge . Edge connects Vertex and Vertex . It is guaranteed that the graph is simple: it has no self-loops and no multi-edges.
There are ways to direct every edge in this graph. We want each vertex to have exactly one edge going from that vertex to another vertex. How many ways are there to direct the edges in that way? Since the answer may be enormous, print it modulo .
Constraints
- All values in input are integers.
- The given graph is simple.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 3
1 2
1 3
2 3
Sample Output 1
2
There are two ways to direct the edges to achieve the objective:
- , ,
- , ,
Sample Input 2
2 1
1 2
Sample Output 2
0
It is obviously impossible to make every vertex have one edge going from that vertex.
Sample Input 3
7 7
1 2
2 3
3 4
4 2
5 6
6 7
7 5
Sample Output 3
4
update @ 2024/3/10 09:55:42