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

14189번 - Explosion at Cafebazaar 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB99151521.127%

문제

You are an engineer at Cafebazaar and your specialty is understanding networks and their behaviors. Your colleagues have designed a network of n switches with m directed links that connect pairs of these switches. Each switch has a buffer where it stores the data and two modes, called sending mode and receiving mode. In the sending mode, a switch sends the data stored in its buffer to each of its outgoing links simultaneously and at the end clears its buffer. In the receiving mode, a switch concatenates the data from all its incoming links and stores them in its buffer, so at the end, the length of the data stored in its buffer is equal to the sum of the lengths of all the data on the incoming links.

Assume that at time t = 0, all the switches are in sending mode and have an empty buffer except switch i which stores a 1-bit package of data in its buffer. Also, all the switches change their modes after each second, so at time t = 1 all the switches change to receiving mode, at time t = 2 they change to sending mode, and so on. Switch i is called explosive if the maximum length of data stored in the buffers of switches is not bounded as t goes to infinity.

Your task is to calculate the number of explosive switches in the network.

입력

There are multiple test cases in the input. The first line of each test case contains two space-separated integers n and m, where n indicates the number of switches and m indicates the number of directed links (1 ≤ n, m ≤ 50, 000). Each of the next m lines contains two space-separated integers u, v where (u, v) indicates a directed link from switch u to switch v (1 ≤ u, v ≤ n, u ≠ v). The input terminates with a line containing 0 0 which should not be processed.

출력

For each test case, output a single line containing the number of explosive switches.

제한

예제 입력 1

3 3
1 2
2 3
3 1
5 6
1 2
2 3
3 1
3 4
4 5
5 3
4 5
1 2
2 3
3 2
3 2
3 4
0 0

예제 출력 1

0
5
3

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > Tehran Site 2016 H번

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

출처

대학교 대회

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

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