luogu#P4610. [COI 2012] KAMPANJA

[COI 2012] KAMPANJA

Background

As the election approaches, the president will give speeches in city 11 and city 22. He travels by car on a campaign tour, starting from 11, passing through city 22 on the way, and finally must return to city 11. The Secret Service monitors all cities the president passes through. To minimize the cost, the number of monitored cities must be as small as possible. Find the minimum number of cities that need to be monitored.

Problem Description

There are NN cities and MM directed edges, satisfying 2N100,2M2002 \le N \le 100, 2 \le M \le 200.

We need to find, among all routes that start from city 11, pass through city 22 on the way, and finally return to city 11, the minimum number of cities that need to be visited. The testdata guarantees that a solution exists.

Input Format

The first line contains two integers N,MN, M. NN is the number of cities, and MM is the number of directed edges.

The next MM lines each contain two integers A,BA, B, indicating a directed edge from AA to BB.

Output Format

Output the minimum number of cities that need to be monitored.

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

Hint

For 100%100\% of the testdata, 2N100,2M2002 \le N \le 100, 2 \le M \le 200 holds.

The testdata for this problem is strengthened by Imagine.

Translated by ChatGPT 5