Triangular Cactus Paths
Time limit2sMemory limit1024 MB
Count simple paths of exact length k between s and f in a triangular cactus graph for each query, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Graph, Tree, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a simple connected undirected graph that is a cactus: each edge lies on at most one simple cycle. This cactus is triangular: the length of any simple cycle is at most .
Answer the queries. In each query, you are given two vertices and , and an integer . Find the number of simple paths between vertices and with length exactly . You should find this number modulo .
The path is simple if all its vertices are different. The length of the path is the number of edges on the path.
Input
The first line contains two integers , (, ), the number of vertices and edges in the graph.
Each of the next lines contains two integers , (, ), meaning that there is an undirected edge in the graph. All edges are different. It is guaranteed that the graph is a connected triangular cactus.
The next line contains a single integer (), the number of queries.
Each of the next lines contains three integers , , (, ), describing a query.
Output
Print integers, one answer per query.