Logo
(追記) (追記ここまで)

26223번 - Inspection 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB0000.000%

문제

A government inspector is coming to your county to check the quality of roads. You want to pass the inspection with minimal effort and expenses, so you're planning to take the inspector on a planned round trip between towns, in order to avoid repairing roads all over the county. Any road in the county goes straight from one town to another, and all roads are one-way. To drive the inspector around successfully, you may have to build new roads. Note that roads going out of a town and back again to the same town are forbidden, and building them even to fool state inspectors is considered bad taste. However, you can build as many roads between any two towns as you want, with arbitrary directions. Define the minimal number of roads to be built in order to take the inspector on a round trip. The length of the trip does not matter.

입력

The first line of the input file contains two integers: $N$ --- the number of towns and $M$ --- the number of one-way roads in the county (1ドル \le N \le 10^5,ドル 0ドル \le M \le 10^5$).

The remaining $M$ lines of the file contain the descriptions of the available roads in the county. For each road, a separate line contains two integers: $A$ --- the number of the town where the road begins and $B$ --- the number of the town where the road ends (1ドル \le A \neq B \le N$). All towns are numbered with integers from 1ドル$ to $N$.

출력

The output file must contain a single integer --- the minimal number of roads that must be built in order to be able to take the inspector on a round trip between the towns. If that is impossible, print $-1$.

제한

예제 입력 1

2 5
2 1
2 1
2 1
2 1
1 2

예제 출력 1

0

예제 입력 2

3 2
2 3
1 2

예제 출력 2

1

힌트

출처

Contest > Open Cup > 2016/2017 Season > Stage 2: Grand Prix of Eurasia 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /