Universal Cup Judging System

Universal Cup

Time Limit: 1.5 s Memory Limit: 256 MB Total points: 100 Hackable ✓
Statistics

Bạn được cho một đồ thị có hướng gồm $n$ đỉnh và $m$ cạnh. Nhiệm vụ của bạn là tìm độ dài của dãy $a$ dài nhất gồm các số nguyên phân biệt từ $1$ đến $n$ sao cho điều kiện sau được thỏa mãn:

  • Gọi $l$ là độ dài của $a$. Khi đó với mọi số nguyên $i \in [2, l]$ và mọi đỉnh $v$ mà tồn tại cạnh $(v, a_i)$, luôn tồn tại một chỉ số $j < i$ sao cho $a_j = v$.

Dữ liệu vào

Dòng đầu tiên chứa $2$ số nguyên $n, m$ ($2 \le n \le 3 \cdot 10^5, 0 \le m \le 3 \cdot 10^5$) — số đỉnh và số cạnh của đồ thị.

$m$ dòng tiếp theo chứa các cặp số nguyên $u_i, v_i$ ($1 \le u_i, v_i \le n$) — các cạnh của đồ thị. Đồ thị có thể có khuyên và cạnh bội.

Kết quả

Trên dòng đầu tiên, in ra độ dài lớn nhất $l$ của dãy hợp lệ.

Ví dụ

Dữ liệu vào 1

5 0

Kết quả 1

5

Dữ liệu vào 2

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

Kết quả 2

5

Dữ liệu vào 3

3 3
1 1
2 2
3 3

Kết quả 3

1

Giải thích

Ở ví dụ đầu tiên, một trong các dãy hợp lệ có thể là $\{1, 2, 3, 4, 5\}$.

Ở ví dụ thứ hai, một trong các dãy hợp lệ có thể là $\{3, 5, 1, 2, 4\}$.

Ở ví dụ thứ ba, một trong các dãy hợp lệ có thể là $\{1\}$. Các dãy $\{2\}$ và $\{3\}$ cũng thỏa mãn điều kiện của bài toán.

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.