Universal Cup Judging System

Universal Cup

时间限制: 1.5 s 内存限制: 256 MB 总分: 100 可 Hack ✓
统计

$n$ 個の頂点と $m$ 本の辺からなる有向グラフが与えられます。あなたの課題は、$1$ から $n$ までの相異なる整数からなる列 $a$ であって、以下の条件を満たすものの最大の長さを求めることです:

  • $a$ の長さを $l$ とします。このとき、すべての整数 $i \in [2, l]$ および辺 $(v, a_i)$ が存在するようなすべての頂点 $v$ に対して、$a_j = v$ となる添字 $j < i$ が存在する。

入力

最初の行には、グラフの頂点数と辺数を表す $2$ つの整数 $n, m$ ($2 \le n \le 3 \cdot 10^5, 0 \le m \le 3 \cdot 10^5$) が与えられます。

続く $m$ 行には、グラフの辺を表す整数の組 $u_i, v_i$ ($1 \le u_i, v_i \le n$) が与えられます。グラフには自己ループや多重辺が含まれる場合があります。

出力

条件を満たす列の最大の長さ $l$ を $1$ 行目に出力してください。

入出力例

入力例 1

5 0

出力例 1

5

入力例 2

5 5
1 2
3 2
2 4
3 5
5 3

出力例 2

5

入力例 3

3 3
1 1
2 2
3 3

出力例 3

1

注記

$1$ 番目のサンプルでは、条件を満たす列の $1$ つとして $\{1, 2, 3, 4, 5\}$ が挙げられます。

$2$ 番目のサンプルでは、条件を満たす列の $1$ つとして $\{3, 5, 1, 2, 4\}$ が挙げられます。

$3$ 番目のサンプルでは、条件を満たす列の $1$ つとして $\{1\}$ が挙げられます。列 $\{2\}$ および $\{3\}$ も問題の条件を満たします。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#370EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.