QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21118. 青草鑑賞家

Statistics

為了更好管理乳牛放牧,Farmer John 在農場鋪設單向牛道。農場有 $N$ 塊田,編號 $1..N$,每條單向道路連接兩塊田。例如從 $X$ 到 $Y$ 的道路允許從 $X$ 去 $Y$,不允許反向。

Bessie 喜歡盡可能多地在不同田裡吃草。每天從田 $1$ 開始,經過一系列田,最後返回田 $1$。她想讓路線經過的不同田最多,因為每塊都能吃草;重複到訪只吃一次。

她不喜歡單向限制,因為它會減少可到訪的不同田數。她想知道,若違反規則,最多逆向走一次道路,能吃多少草。求從田 $1$ 出發並返回、最多有一次逆向通行的路線中,不同田的最大數量。整個旅程最多逆向一次,甚至不能把同一條道路逆向走兩次。

輸入格式

第一行包含田數 $N$、單向道路數 $M$($1 \leq N, M \leq 100,000$)。

接下來 $M$ 行各描述一條單向道路,包含不同田號 $X$、$Y$,表示從 $X$ 到 $Y$。同一條道路不會重複出現。

輸出格式

輸出一行,為從田 $1$ 出發並返回、最多逆向走一次道路時能到訪的不同田數最大值。

範例

輸入格式 1

7 10
1 2
3 1
2 5
2 4
3 7
3 5
3 6
6 5
7 2
4 7

輸出格式 1

6

說明

範例輸入的 ASCII 圖如下:

v---3-->6
7   |\  |
^\  v \ |
| \ 1  \|
|  \|   v
|   v   5
4<--2---^

她可以沿 $1,2,4,7,2,5,3,1$ 到訪,逆向通過 $5$ 與 $3$ 之間的道路。到達 $3$ 後,若不再逆向走另一條道路,就無法到達 $6$。

題目作者:Mark Gordon,2015

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.