QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#10665. Evacuation [A]

Statistics

Due to an increasing terrorist threat the Agency for Defending Byteland (ADB) has decided to prepare a plan of action for the case of an attack. The key issue for the agency is to make sure that the king of Byteland has a possibility of a quick evacuation when a bombing takes place.

The royal palace is located next to one of the junctions in the capital of Byteland. Next to another junction there is a shelter to which the king should immediately be transported in the case of a threat. The agency has a precise road network plan of the capital, consisting of junctions connected with unidirectional streets.

An evacuation route is considered quick if it consists of up to three streets. If a bombing takes place at some street, it becomes unpassable for the royal convoy. ADB has asked you to find out, what is the minimal number of streets that need to be bombed so that the king would not have any quick evacuation route.

Input Format

The first line of the standard input contains two integers $ n $ and $ m $ (2 ≤ $ n $ ≤ 1 000, 0 ≤ $ m $ ≤ $ n $($ n $-1)) denoting the number of junctions and the number of streets in the capital of Byteland. The junctions are numbered from 1 to $ n $; the royal palace is located next to the junction number 1, and the shelter next to the junction number $ n $.

The following $ m $ lines contain a description of the streets in the capital. The $ i $-th of these lines contains two integers $ a_{i} $, $ b_{i} $ (1 ≤ $ a_{i} $, $ b_{i} $ ≤ $ n $, $ a_{i} $ ≠ $ b_{i} $) representing a unidirectional street starting at junction number $ a_{i} $ and ending at junction number $ b_{i} $. For each ordered pair of junctions, these exists at most one street going from the first one to the second one.

Output Format

Your program should write to the standard output exactly one integer - the minimal number of streets that must be bombed by terrorists so that the king does not have any quick evacuation route.

Example

Input

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

Output

2
problem_10665_1.gif

For the king not to have any quick evacuation route, it suffices to bomb the streets 1 → 3 and 3 → 5 (they are crossed out in the above figure).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.