Problem Statement There is a simple directed graph G with N vertices and N+M edges. The…
- User
Problem Statement There is a simple directed graph G with N vertices and N+M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to N+M.
Edge i goes from vertex i to vertex i+1. (Here, vertex N+1 is considered as vertex 1.) Edge N+i (1≤i≤M) goes from vertex X i to vertex Y i .
Takahashi is at vertex
At each vertex, he can move to any vertex to which there is an outgoing edge from the current vertex. Compute the number of ways he can move exactly K times.
That is, find the number of integer sequences (v 0 ,v 1 ,…,v K ) of length K+1 satisfying all of the following three conditions:
1≤v i ≤N for i=0,1,…,K. v 0 =1. There is a directed edge from vertex v i−1 to vertex v i for i=1,2,…,K. Since this number can be very large, print it modulo 998244353.
Constraints 2≤N≤2×10 5
0≤M≤50 1≤K≤2×10 5
1≤X i ,Y i ≤N, X i
=Y i
All of the N+M directed edges are distinct. All input values are integers. Input The input is given from Standard Input in the following format:
N M K X 1
Y 1
X 2
Y 2
⋮ X M
Y M
Output Print the count modulo 998244353.
- Assistant
To solve this problem, we need to find the number of ways Takahashi can move exactly ( K ) times on a special directed graph.
Observation:
-
Base Cycle:
- The graph contains a base cycle where each vertex ( i ) has an edge to ( i+1 \mod N ).
- Starting from vertex ( 1 ), moving along the base cycle, Takahashi can only reach vertex ( (1 + K) \mod N ) after ( K ) steps.
- This means that without the ( M ) additional edges, there's exactly one path Takahashi can take.
-
Additional Edges:
- There are ( M ) additional edges.
- However, ( M ) is up to ( 50 ), which is very small compared to ( N ) and ( K ).
- These additional edges can only create a limited number of new paths.
- But since ( K ) can be as big as ( 2 \times 10^5 ), the influence of these additional edges is negligible in terms of creating a vast number of new paths.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.