Cactus Automorphisms
Time limit5sMemory limit256 MB
Count the automorphisms of a given cactus graph with up to 50000 vertices and print the count as a prime factorization.
- Level
Hard9 of 10
- Topics
- Tree, Dynamic programming, Combinatorics, Number theory
- Solved
- No attempts yet
Problem
A cactus is a connected undirected graph in which every edge belongs to at most one simple cycle. Think of it as a tree that is allowed a few cycles. NEERC has been setting problems about cactuses for years. In 2005, the first year one appeared, the problem was called simply Cactus. In 2007 it was Cactus Reloaded, and in 2010 it was Cactus Revolution.
Preparing test data for those problems runs into one difficulty. Some wrong solutions behave differently depending on how the vertices are numbered in the input, so for the most interesting tests the judges include the same graph several times with different numbering. Some graphs are regular enough that renumbering the vertices leaves the graph unchanged. To decide objectively how many tests a graph deserves, the judges want a number that says how regular that graph is.
That number is the count of graph automorphisms. Let be an undirected graph, where is a set of vertices and is a set of edges, and each edge is a set of two distinct vertices with . A graph automorphism is a bijection from onto such that for every pair of vertices and joined by an edge (so ), the condition holds.
Every graph has at least one automorphism, the identity, and a graph with vertices has at most of them. The count can be very large, so the answer must be written as a prime factorization , where the are primes in ascending order (, ) and the are the matching exponents ().
Input
The first line contains two integers and (, ). Here is the number of vertices in the graph, numbered from to . The edges of the graph are given as a set of edge-distinct paths, and is the number of those paths.
Each of the next lines contains one path. A path starts with an integer () followed by integers from to . Those integers are the vertices of the path in order. Adjacent vertices in a path are distinct. A path may visit the same vertex several times, but every edge is traversed exactly once in the whole input. There are no multiedges: at most one edge joins any two vertices.
The graph in the input is a cactus.
Output
On the first line print the number of prime factors in the factorization of the number of graph automorphisms. Print if the number of graph automorphisms is . On each of the next lines print a prime and its power separated by a space. The primes must be given in ascending order.
Hint
The graph in the first example has automorphisms.
The second example is a simple graph with two vertices and one edge between them, which has automorphisms.
The third example is a star graph with a center vertex and rays, which has automorphisms.