Universal Cup Judging System

Universal Cup

実行時間制限: 1.5 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓
統計

給定一個具有 $n$ 個頂點和 $m$ 條邊的有向圖。你的任務是找出由 $1$ 到 $n$ 之間相異整數組成的最長序列 $a$ 的長度,使得滿足以下條件:

  • 設 $l$ 為 $a$ 的長度。那麼對於所有整數 $i \in [2, l]$ 以及所有滿足存在邊 $(v, a_i)$ 的頂點 $v$,都存在一個指標 $j < i$ 使得 $a_j = v$。

輸入格式

第一行包含 $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

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, 2, 3, 4, 5\}$。

在第二個範例中,一個合法的序列可以是 $\{3, 5, 1, 2, 4\}$。

在第三個範例中,一個合法的序列可以是 $\{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.