CF1442C.Graph Transpositions

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a directed graph of nn vertices and mm edges. Vertices are numbered from 11 to nn . There is a token in vertex 11 .

The following actions are allowed:

  • Token movement. To move the token from vertex uu to vertex vv if there is an edge uvu \to v in the graph. This action takes 11 second.
  • Graph transposition. To transpose all the edges in the graph: replace each edge uvu \to v by an edge vuv \to u . This action takes increasingly more time: kk -th transposition takes 2k12^{k-1} seconds, i.e. the first transposition takes 11 second, the second one takes 22 seconds, the third one takes 44 seconds, and so on.

The goal is to move the token from vertex 11 to vertex nn in the shortest possible time. Print this time modulo 998244353998\,244\,353 .

输入格式

The first line of input contains two integers n,mn, m ( 1n,m2000001 \le n, m \le 200\,000 ).

The next mm lines contain two integers each: u,vu, v ( 1u,vn;uv1 \le u, v \le n; u \ne v ), which represent the edges of the graph. It is guaranteed that all ordered pairs (u,v)(u, v) are distinct.

It is guaranteed that it is possible to move the token from vertex 11 to vertex nn using the actions above.

输出格式

Print one integer: the minimum required time modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    4 4
    1 2
    2 3
    3 4
    4 1

    输出#1

    2
  • 输入#2

    4 3
    2 1
    2 3
    4 3

    输出#2

    10

说明/提示

The first example can be solved by transposing the graph and moving the token to vertex 44 , taking 22 seconds.

The best way to solve the second example is the following: transpose the graph, move the token to vertex 22 , transpose the graph again, move the token to vertex 33 , transpose the graph once more and move the token to vertex 44 .

首页