• محدودیت زمان: ۶ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

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=0t = 0, all the switches are in sending mode and have an empty buffer except switch ii which stores a 11-bit package of data in its buffer. Also, all the switches change their modes after each second, so at time t=1t = 1 all the switches change to receiving mode, at time t=2t = 2 they change to sending mode, and so on. Switch ii is called explosive if the maximum length of data stored in the buffers of switches is not bounded as tt 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 nn and mm, where nn indicates the number of switches and mm indicates the number of directed links (1n,m50,0001 \leq n, m \leq 50 , 000). Each of the next mm lines contains two space-separated integers u,vu, v where (u,v)(u, v) indicates a directed link from switch uu to switch vv (1uvn1 \leq u \neq v \leq n). The input terminates with a line containing 00 00 which should not be processed.

خروجی

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

مثال

ورودی نمونه ۱

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
Plain text

خروجی نمونه ۱

0
5
3
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.