PivotOJ

Locking Doors

시간 제한: 5000ms메모리 제한: 1024MB출처: BAPC 2023BOJ 30500

문제

You just started a new job at a shopping mall, and as it goes, you got the shittiest task of all: closing down at night. The mall consists of many rooms (which can be shops, hallways, or other public spaces) with open doors between them that must be closed. You can walk through a door both ways if it is open, but annoyingly, each door can only be locked from one of the two rooms it connects.

Your supervisor already locked the main entrance of the shopping mall, and left you inside with the task to lock all the doors. In order to do so, you may request additional exits to be installed in some of the rooms. If a room has an exit, then you are able to enter or leave the shopping mall through that room.

What is the minimal number of exits you need to request in order for it to be possible to lock all the doors and then leave the building?

입력

The input consists of:

  • One line with two integers nn and mm (2n1052\leq n \leq 10^5, 1m1061\leq m \leq 10^6), the number of rooms and doors, respectively.
  • Then follow mm lines, each containing two distinct integers aa and bb (1a,bn1 \leq a,b \leq n, aba \neq b), indicating a door connecting rooms aa and bb which can only be locked from room aa.

You may assume that all ordered pairs (a,b)(a,b) are distinct and that you can walk from any room in the mall to any other room if all the doors are open.

출력

Output the minimal number of exits that need to be installed.

예제

예제 1

입력
2 1
1 2
출력
1

예제 2

입력
3 2
2 1
3 1
출력
2

예제 3

입력
5 4
1 2
3 1
4 1
5 1
출력
3

예제 4

입력
10 14
1 2
2 1
3 4
3 5
4 6
5 6
6 3
7 8
8 9
9 7
1 8
2 10
4 9
5 10
출력
2
코드를 제출하려면 로그인하세요.