Universal Cup Judging System

Universal Cup

Limite de temps : 1.5 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓
Statistiques

$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

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.