Travel
Time limit2.5sMemory limit256 MB
Count pairs of paths covering every vertex of a directed graph with at most one cycle per vertex, each vertex used at most k times in total, mod 998244353.
- Level
Hard9 of 10
- Topics
- Graph, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
"I'm tired of seeing the same scenery in the world." --- Philosopher Pang
Pang's world can be simplified as a directed graph with vertices and edges.
A path in is an ordered list of vertices for some non-negative integer such that is an edge in for all . A path can be empty.
A cycle in is an ordered list of distinct vertices for some integer such that is an edge in for all . All circular shifts of a cycle are considered the same.
satisfies the following property: every vertex is in at most one cycle.
Given a fixed integer , count the number of pairs modulo such that:
- and are paths.
- For every vertex , is in or .
- Let be the number of occurrences of in path . For every vertex of , .
The time limit is 2500 ms and the memory limit is 256 MB.
Input
The first line contains three integers , , and (, , ).
Each of the next lines contains two integers and , denoting an edge from vertex to vertex (, ). No two edges connect the same pair of vertices in the same direction.
Output
Output one integer: the number of pairs modulo .