Universal Cup Judging System

Universal Cup

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

נתון לכם גרף מכוון עם $n$ צמתים ו-$m$ קשתות. משימתכם היא למצוא את אורכה של הסדרה הארוכה ביותר $a$ של מספרים שלמים שונים מ-$1$ עד $n$ כך שהתנאי הבא מתקיים:

  • יהי $l$ האורך של $a$. אזי לכל המספרים השלמים $i \in [2, l]$ ולכל הצמתים $v$ שעבורם קיימת קשת $(v, a_i)$, קיים אינדקס $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.