Horrible Cycles
Time limit2sMemory limit512 MB
Count the simple cycles in a bipartite graph where each left vertex i connects to the right prefix 1 to a_i, modulo 998244353, with n up to 5000.
- Level
Hard8 of 10
- Topics
- Graph, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a bipartite graph with vertices in each part. In this graph, each vertex from the left part is connected to some prefix of vertices from the right part. Namely, the -th vertex in the left part is connected with vertices in the right part.
Find the number of vertex-simple cycles in this graph. Two cycles are different if there exists some edge that is present in one cycle but not in the other.
As this number may be large, output it modulo .
Input
The first line contains one integer (): the number of vertices in each part.
The second line contains integers (): a description of the graph.
Output
Output one integer: the number of vertex-simple cycles in the given graph, modulo .