Problem:
   Problem Statement We have N boxes, numbered 1 through N . At first, box 1 contains one red ball, and each of the other boxes contains one white ball.  Snuke will perform the following M operations, one by one. In the i -th operation, he randomly picks one ball from box x_i , then he puts it into box y_i .  Find the number of boxes that may contain the red ball after all operations are performed.      Constraints  2≤N≤10^5  1≤M≤10^5  1≤x_i,y_i≤N  x_i≠y_i  Just before the i -th operation is performed, box x_i contains at least 1 ball.         Input The input is given from Standard Input in the following format:  N  M  x_1  y_1  :  x_M  y_M       Output Print the number of boxes that may contain the red ball after all operations are performed.        Sample Input 1 3 2
1 2
2 3      Sample Output 1 2  Just after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.  Now, consider the second operation. If Snuke picks the red ball from box 2 , the red ball will go into box 3 . If he picks the white ball instead, the red ball will stay in box 2 .
Thus, the number of boxes that may contain the red ball after all operations, is 2 .       Sample Input 2 3 3
1 2
2 3
2 3      Sample Output 2 1  All balls will go into box 3 .       Sample Input 3 4 4
1 2
2 3
4 1
3 4      Sample Output 3 3

Solution (Python):


from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    red = [False] * n
    red[0] = True
    balls = [1] * n
    ans = 1
    for _ in range(m):
        x, y = map(int, input().split())
        if red[x - 1]:
            if balls[x - 1] == 1:
                red[x - 1] = False
                ans -= 1
            if not red[y - 1]:
                red[y - 1] = True
                ans += 1
        balls[x - 1] -= 1
        balls[y - 1] += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
n, m = map(int, input().split())
nums = [1 for _ in range(n)]
tf = [False for _ in range(n)]
tf[0] = True

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    nums[x] -= 1
    nums[y] += 1
    if tf[x]:
        tf[y] = True
        if nums[x] == 0:
            tf[x] = False
print(tf.count(True))

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	n, m = tin()
	
	is_red_in = [0]*n
	is_red_in[0] = 1
	num_of_ball = [1] * n
	for _ in range(m):
		f, t = tin()
		f, t = f-1, t-1
		num_of_ball[f] -= 1
		num_of_ball[t] += 1
		if is_red_in[f] == 1:
			is_red_in[t] = 1
		if num_of_ball[f] == 0:
			is_red_in[f] = 0
	return sum(is_red_in)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n, m = map(int, input().split())
box = [1] * n
red = [0] * n
red[0] = 1
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    if box[a]:
        if red[a] == 1:
            red[b] = 1

        if box[a] == 1:
            if red[a] == 1:
                red[a] = 0

        box[a] -= 1
        box[b] += 1

print(sum(red))

Solution (Python):
n, m = map(int, input().split())
box = [1]*(n+1)
red = [False]*(n+1)
red[1] = True

for i in range(m):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        red[x] = False

print(red.count(True))

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
c = [1]*n
r = set([0])
for i in range(m):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    if c[x]==1 and x in r:
        r.remove(x)
        r.add(y)
    elif c[x]>=2 and x in r:
        r.add(y)
    c[x] -= 1
    c[y] += 1
print(len(r))

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n, m = map(int, input().split())
    ball, can = [1]*n, [False]*n
    can[0] = True
    for _ in range(m):
        x, y = map(int, input().split())
        if can[x-1] == True:
            can[y-1] = True
        ball[x-1] -= 1
        ball[y-1] += 1
        if ball[x-1] == 0:
            can[x-1] = False
    print(can.count(True))
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N,M = map(int,input().split())
C = {i:[1,0] for i in range(1,N+1)}
C[1] = [1,1]
for _ in range(M):
    x,y = map(int,input().split())
    C[y][0] += 1
    if C[x][1]==1:
        C[y][1] = 1
    C[x][0] -= 1
    if C[x][0]==0:
        C[x][1]=0
cnt = 0
for i in range(1,N+1):
    if C[i][1]==1:
        cnt += 1
print(cnt)

Solution (Python):
n, m = map(int, input().split())
C = [0]*(n+1)
C[1] = 1
D = [1]*(n+1)
for _ in range(m):
  x, y = map(int, input().split())
  if C[x]:
    C[y] = 1
    if D[x] == 1:
      C[x] = 0
  D[x] -= 1
  D[y] += 1
ans = sum(C)
print(ans)

Solution (Python):
n,m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

box = [1]*(n+1)
red = [0]*(n+1)
red[1] = 1
for x,y in xy:
    box[x] -= 1
    box[y] += 1
    if red[x]==1: red[y] = 1
    if box[x]==0: red[x] = 0
print(sum(red))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, M = inm()


def solve():
    pos = {0}
    count = [1] * N
    for i in range(M):
        x, y = inm()
        x -= 1
        y -= 1
        if x in pos:
            if count[x] == 1:
                pos.remove(x)
            pos.add(y)
        count[x] -= 1
        count[y] += 1
    return len(pos)


print(solve())

Solution (Python):
N,M=map(int,input().split())
X=[0]*(N+1)
X[1]=1
Y=[1]*(N+1)
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  X[b]|=X[a]
  Y[b]+=1
  Y[a]-=1
  if Y[a]==0:
    X[a]=0
print(sum(X))

Solution (Python):
N, M = map(int, input().split())

red = [0]*N
red[0] = 1
white = [1]*N
white[0] = 0
ans = 1
for i in range(M):
    a, b = map(int, input().split())
    if red[a-1] == 1:
        if red[b-1] == 0:
            red[b-1] += 1
            ans += 1
        else:
            white[b-1] += 1

        if white[a-1] > 0:
            white[a-1] -= 1
        else:
            red[a-1] -= 1
            ans -= 1
    elif white[a-1] > 0:
        white[a-1] -= 1
        white[b-1] += 1
print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N, M = I()
a = []
c = [1]*N
red = [0]*N
red[0] = 1

for i in range(M):
    x = l()
    a.append(x)
    c[x[0]-1] -= 1
    c[x[1]-1] += 1
    if red[x[0]-1]:
        red[x[1]-1] = 1
    if not c[x[0]-1]:
        red[x[0]-1] = 0


print(sum(red))

Solution (Python):
n, m = map(int,input().split())
b_list = []

for i in range(m):
    x = []
    x = list(map(int,input().split()))
    b_list.append(x)

ans_list = [0 for i in range(10**5)]
ans_list[0] = 1
ball_list = [1 for i in range(10**5)]

for tmp in b_list:
    x, y = tmp[0], tmp[1]
    if ans_list[x-1] == 1 and ans_list[y-1] == 0:
        ans_list[y-1] += 1
    ball_list[y-1] += 1
    ball_list[x-1] -= 1
    if ball_list[x-1] == 0:
        ans_list[x-1] = 0

ans = 0

for i in ans_list:
    if i == 1:
        ans += 1

print(ans)

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    XY = [tuple(map(int, input().split())) for _ in [0] * M]

    box = [1] * (N + 1)
    red = [0] * (N + 1)
    box[0], red[1] = 0, 1
    for x, y in XY:
        box[x] -= 1
        box[y] += 1
        if red[x]:
            red[y] = 1
        if not box[x]:
            red[x] = 0
    print(sum(red))


main()

Solution (Python):
n,m=map(int,input().split())
flg=[False for i in range(n)]
flg[0]=True
t=[1 for i in range(n)]
tmp=1
for i in range(m):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    t[x]-=1
    t[y]+=1
    if flg[x]:
        flg[y]=True
        if t[x]==1 and len(flg)==1:
            flg[x]=False

    if t[x]==0:
        flg[x]=False
ans=0
for i in range(n):
    if flg[i]:
        ans+=1
print(ans)

Solution (Python):
from collections import defaultdict

N, M = map(int, input().split())

ball_count=[1 for _ in range(N)]
redExist=[0 for _ in range(N)]
redExist[0]=1
for m in range(M):
  x, y = map(int, input().split())
  
  x-=1
  y-=1

  ball_count[x] -= 1
  ball_count[y] += 1
  if (redExist[x]):
    redExist[y]=True
  if ball_count[x] == 0:
    redExist[x]=False
print(len([b for b in redExist if b]))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
res = [False] * n
res[0] = True
cnt = [1] * n
for i in range(m):
    a,b = inpl()
    a,b = a-1,b-1
    cnt[a] -= 1; cnt[b] += 1
    if res[a]:
        res[b] = True
    if cnt[a] == 0:
        res[a] = False
print(sum(res))

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
box = [1] * n
nya = [True] + [False]*(n-1)
for i in range(m):
    x,y = map(lambda x:int(x)-1,input().split())
    
    
    
    
    
    
    
    
    
    
    
    
    
    box[x] -= 1
    box[y] += 1
    if nya[x]:
        nya[y] = True
    if box[x] == 0:
        nya[x] = False
print(nya.count(True))

Solution (Python):
def solve():
    ans = 0
    N, M = map(int, input().split())
    lis = [1]*N
    lis[0] = -1 
    for _ in range(M):
        x,y = map(int, input().split())
        x -= 1
        y -= 1
        if lis[x]<0:
            lis[y] = -(abs(lis[y])+1)
            lis[x] += 1
        else:
            if lis[y]==0:
                lis[y] = 1
            else:
                lis[y] = (abs(lis[y])+1)*lis[y]//abs(lis[y])
            lis[x] -= 1
    ans = sum(map(lambda x:x<0,lis))
    return ans
print(solve())

Solution (Python):
n, m = map(int, input().split())
red = [0]*n
ball = [1]*n
red[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    if red[x-1] == 1:
        red[y-1] = 1
        if ball[x-1] == 1:
            red[x-1] = 0
    ball[y-1] += 1
    ball[x-1] -= 1
print(sum(red))

Solution (Python):
N,M = map(int,input().split())
A = [0 for _ in range(N+1)]
B = [1 for _ in range(N+1)]
A[1] = 1
B[0] = 0
for _ in range(M):
    x,y = map(int,input().split())
    if A[x]==1:
        A[y]=1
    B[y] += 1
    B[x] -= 1
    if B[x]==0:
        A[x] = 0
print(sum(A))

Solution (Python):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
red = [0] * (N + 1)
white = [1] * (N + 1)
red[1] = 1
white[1] = 0

for _ in range(M):
    x, y = map(int, input().split())
    if red[x]:
        red[y] += 1
    else:
        white[y] += 1
    if white[x]:
        white[x] -= 1
    else:
        red[x] -= 1

print(N-red[1:].count(0))

Solution (Python):
N,M = map(int,input().split())

ans = [0]*N
ans[0] = 1
ball = [1]*N

for _ in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    if ans[x]:
        ans[y] = 1
    ball[x] -= 1
    ball[y] += 1

    if not ball[x]:
        ans[x] = 0

print(sum([i*(j>0) for i,j in zip(ans,ball)]))

Solution (Python):
n,m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

box = [1]*(n+1)
red = [0]*(n+1)
red[1] = 1
for x,y in xy:
    box[x] -= 1
    box[y] += 1
    if red[x] == 1: red[y] = 1
    if box[x] == 0: red[x] = 0
print(red.count(1))

Solution (Python):
n, m = map(int, input().split())

X = [0]*n
C = [1]*n
X[0] = 1

for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    if X[x] == 1:
        X[y] = 1
        if C[x] == 1:
            X[x] = 0
        C[x] -= 1
        C[y] += 1
    else:
        C[x] -= 1
        C[y] += 1

ans = sum(X)
print(ans)

Solution (Python):
n, m = map(int, input().split())
num = [1] * n
red = [False] * n
red[0] = True
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x]:
        red[y] = True
    num[x] -= 1
    num[y] += 1
    if num[x] == 0:
        red[x] = False
ans = 0
for r in red:
    ans += r
print(ans)

Solution (Python):
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ball_cnt = [1] * 10**6
check = [0] * 10**6

check[1] += 1

for i in range(m):
    x = li[i][0]
    y = li[i][1]
    
    if check[x] == 1:
        check[y] = 1
    
    ball_cnt[x] -= 1
    ball_cnt[y] += 1
    
    if ball_cnt[x] == 0:
        check[x] = 0
        
print(sum(check))

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N, M = read_ints()
X, Y = read_col(M)
X = mina(*X)
Y = mina(*Y)



prob = [False] * N
n_balls = [1] * N
prob[0] = True

for x, y in zip(X, Y):
    prob[y] = prob[y] or prob[x]
    n_balls[x] -= 1
    n_balls[y] += 1
    if n_balls[x] == 0:
        prob[x] = False


print(sum(prob))

Solution (Python):
import numpy as np

N, M = map(int,input().split())

box = np.array([1]*N)
pos = np.array([0]*N)
pos[0] = 1

for i in range(M):
    x, y = map(lambda x:int(x)-1,input().split())
    box[x] -= 1
    box[y] += 1
    if pos[x]:
        pos[y] = 1
        if box[x] == 0:
            pos[x] = 0




box = np.where(box > 0, 1, 0)
print(sum(pos*box))

Solution (Python):
n,m=map(int,input().split())
l=[1]+[0]*(n+1)
a=[1]*n
for i in range(m):
 x,y=map(int,input().split())
 if l[x-1]:l[y-1]=1
 a[x-1]-=1;a[y-1]+=1
 if not a[x-1]:l[x-1]=0
print(l.count(1))

Solution (Python):
n,m=map(int,input().split())
xy = [list(map(int, input().split())) for _ in range(m)]
l=[1]*n
out_=[0]*n
in_=[0]*n
c=1

check=0
for i in range(m):
    if check==0:
        if xy[i][0]==1:
            in_[xy[i][1]-1]+=1
            check=1
        else:
            if xy[i][1]==1:
                in_[xy[i][1]-1]+=1
                check=1
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
    else:
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
        if l[xy[i][0]-1]==0 and in_[xy[i][0]-1]!=0:
            in_[xy[i][0]-1]=0
            in_[xy[i][1]-1]+=1
        elif l[xy[i][0]-1]!=0 and in_[xy[i][0]-1]!=0:
            in_[xy[i][1]-1]+=1
ans=0
for i in range(n):
    if in_[i]!=0:
        ans+=1
print(ans)

Solution (Python):
n,m=map(int,input().split())
xy = [list(map(int, input().split())) for _ in range(m)]
l=[1]*n
out_=[0]*n
in_=[0]*n
c=1

check=0
for i in range(m):
    if check==0:
        if xy[i][0]==1:
            in_[xy[i][1]-1]+=1
            check=1
        else:
            if xy[i][1]==1:
                in_[xy[i][1]-1]+=1
                check=1
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
        
    else:
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
        if l[xy[i][0]-1]==0 and in_[xy[i][0]-1]!=0:
            in_[xy[i][0]-1]=0
            in_[xy[i][1]-1]+=1
        elif l[xy[i][0]-1]!=0 and in_[xy[i][0]-1]!=0:
            in_[xy[i][1]-1]+=1
        

ans=0
for i in range(n):
    if in_[i]!=0:
        ans+=1
print(ans)

Solution (Python):
N,M=map(int,input().split())
R=[True]+[False]*(N-1)
B=[1]*N
for i in range(M):
    x,y=map(int,input().split())
    if R[x-1]:
        R[y-1]=True
    B[x-1]-=1
    B[y-1]+=1
    if B[x-1]==0:
        R[x-1]=False
print(R.count(True))

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
m = map(int, read().split())

count = [1] * (N+1)
red = [0] * (N+1)
red[1] = True
for x, y in zip(m, m):
    count[x] -= 1
    count[y] += 1
    if red[x]:
        red[y] = 1
    if not count[x]:
        red[x] = 0

print(sum(red))

Solution (Python):
def main():
    n,m = map(int,input().split())
    box = [1] * n
    red = [0] * n
    red[0] += 1
    op = [list(map(int,input().split())) for _ in range(m)]
    for o in op:
        x, y = o[0]-1, o[1]-1
        if box[x] < 1:
            continue
        box[x] -= 1
        if red[x] > 0:
            red[y] = 1
        if box[x] == 0:
            red[x] = 0
        box[y] += 1
    print(sum(red))

if __name__ == "__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
red=[1]+[0]*(n-1)
pink=[1]*n
for _ in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if red[x] and pink[x]==1:
        red[x]=0
        red[y]=1
    elif red[x] and pink[x]>1:
        red[y]=1
    pink[x]-=1
    pink[y]+=1
print(red.count(1))

Solution (Python):
n, m = map(int, input().split())
N = [1]*n
P = [True] + [False]*(n-1)
for i in range(m):
    x, y = list(map(lambda tmp: tmp-1, map(int, input().split())))
    P[y] = True if P[x]==True else P[y]
    N[x] -= 1
    N[y] += 1
    P[x] = False if N[x]==0 else P[x]
print(sum(P))

Solution (Python):
n,m = map(int,input().split())
canred = set()
canred.add(1)
balls = [1 for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    if x in canred:
        canred.add(y)
    balls[x-1]-=1
    balls[y-1] += 1
    if balls[x-1] == 0:
        canred.discard(x)


print(len(canred))

Solution (Python):



def main():
    N, M = map(int, input().split())
    dp = {1:[1,True]}         
    for _ in range(2,N+1):
        dp[_] = [1,False]
    for _ in range(M):
        fm, to = map(int, input().split())
        num, state = dp[fm]
        
        dp[fm][0]-=1    
        if dp[fm][0]==0:
            dp[fm][1] = False
        
        dp[to][0]+=1    
        dp[to][1]=dp[to][1] or state
    ret = 0
    for _ in range(1,N+1):
        ret += dp[_][1]
    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())

Red = [0]*N
Red[0] = 1
Num = [1]*N

for i in range(M):
  In, Out = map(int, input().split())
  In -= 1
  Out -= 1
  Num[In] -= 1
  Num[Out] += 1
  if Red[In]:
    Red[Out] = 1
  if Num[In] == 0:
    Red[In] = 0

print(sum(Red))

Solution (Python):
n_box, n_move = map(int,input().split())
num_balls = [1] * n_box
can_red = [0] * n_box
can_red[0] = 1
for i in range(n_move):
    From, to = map(int,input().split())
    From -= 1
    to -= 1
    if can_red[From] == 1:
        if num_balls[From] == 1:
            can_red[From] = 0
            can_red[to] = 1
        else:
            can_red[to] = 1
    num_balls[From] -= 1
    num_balls[to] += 1

ans = 0
for i in range(n_box):
    if can_red[i] == 1:
        ans += 1
print(ans)

Solution (Python):
n,m = map(int,input().split(" "))
ar = [[0,1] for i in range(n)]
ar[0] = [1,1]
r = 0
for i in range(m):
    a,b = map(int,input().split(" "))
    a -= 1
    b -= 1
    if ar[a][0] == 1 and ar[a][1] >= 1:
        ar[b][0] = 1
    ar[b][1] += 1
    ar[a][1] -= 1
    if ar[a][1] == 0:
        ar[a][0] = 0
count = 0
for r in ar:
    if r[0] == 1:
        count += 1
print(count)

Solution (Python):
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''

def myAnswer(N:int,M:int,X:list,Y:list) -> int:
   ans = {0}
   box = [1] * N
   for x,y in zip(X,Y):
      if(x-1 in ans):
         if(box[x - 1]==1):
            ans.remove(x-1)
         ans.add(y-1)
      box[x-1] -= 1
      box[y-1] += 1
   return len(ans)

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   X = []
   Y = []
   for _ in range(M):
      x,y=map(int,input().split())
      X.append(x)
      Y.append(y)
   print(myAnswer(N,M,X,Y))
if __name__ == '__main__':
   main()

Solution (Python):
n,m = map(int,input().split())
x = [0 for _ in range(m)]
y = [0 for _ in range(m)]
for i in range(m):
    x[i],y[i] = map(int,input().split())
    x[i] -= 1
    y[i] -= 1

box = [1 for _ in range(n)]
red = [0 for _ in range(n)]
red[0] = 1
for i in range(m):
    red[y[i]] = 1 if red[x[i]] else red[y[i]]
    red[x[i]] = red[x[i]] if box[x[i]]-1 else 0
    box[x[i]] -= 1
    box[y[i]] += 1
print(sum(red))

Solution (Python):
n,m = map(int,input().split())

ball = [1]*n
d={}
for i in range(1,n+1):
    d[i]=0
d[1]=1

for _ in range(m):
    x,y = map(int,input().split())

    ball[x-1]-=1
    if d[x]==1:
        if ball[x-1]==0:
            d[x]=0
        d[y]=1
    ball[y-1]+=1

cnt=0
for _ ,v in d.items():
    if v==1:
        cnt+=1


print(cnt)

Solution (Python):
n,m = map(int, input().split())

'''
d = dict()
for i in range(1,n+1):
    d[str(i)] = 1
from collections import deque
ans = deque('1')'''
box = [1 for i in range(n)]
ans = [0 for i in range(n)]
ans[0] = 1
for _ in range(m):
    x,y = map(int,input().split())
    box[x-1] -= 1
    box[y-1] += 1
    if ans[x-1]==1 and ans[y-1]==0:
        ans[y-1] = 1
    if box[x-1]==0 and ans[x-1]==1:
        ans[x-1] = 0
print(sum(ans))

Solution (Python):
import sys
n, m = map(int, input().split())
ball = [1 for i in range(n+1)]
box = [0 for i in range(n+1)]
box[1] = 1
for a in sys.stdin.readlines():
    x, y = map(int, a.split())
    ball[x] -= 1
    ball[y] += 1
    if box[y] == 0 and box[x]:
        box[y] = 1
    if box[x] and ball[x] == 0:
        box[x] = 0

print(sum(box))

Solution (Python):
n, m = [int(_) for _ in input().split()]

ball = [1 for i in range(n)]
red = [False for i in range(n)]
red[0] = True

for i in range(m):
    x, y = [int(_)-1 for _ in input().split()]
    ball[x] -= 1
    ball[y] += 1
    if red[x]:
        red[y] = True
    if ball[x] == 0:
        red[x] = False

print(sum(red))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,M = IL()
data = ILL(M)
count = [1 for i in range(N)]
p = [0 for i in range(N)]
p[0] = 1
for x,y in data:
  x,y = x-1,y-1
  if count[x] == 1:
    p[y] += p[x]
    p[x] = 0
  else:
    N = count[x]
    p[y] += p[x]
  count[x] -= 1
  count[y] += 1
ans = 0
for i in p:
  if i!=0:
    ans += 1
print(ans)

Solution (Python):
N,M=map(int,input().split())
Red=[False]*N
Cnt=[1]*N
Red[0]=True
for i in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    Red[y]|=Red[x]
    Cnt[y]+=1
    Cnt[x]-=1
    if Cnt[x]==0:
        Red[x]=False
ans=0
for i in range(N):
    if Red[i] and Cnt[i]>0:
        ans+=1
print(ans)

Solution (Python):
N, M = map(int, input().split())

ball = [1 for _ in range(N)]
red = [0 for _ in range(N)]
red[0] = 1

now_red = 0

for i in range(M):
    xx, yy = map(int, input().split())
    x = xx-1
    y = yy-1
    
    ball[x] -= 1
    ball[y] += 1
    
    if red[x]:
        if ball[x] == 0:
            red[x] = 0

        red[y] = 1
        now_red = y
    
    
    

print(sum(red))

Solution (Python):
n,m=map(int,input().split())
quant=[1]*(n+1)
prob=[0]*(n+1)
prob[1]=1
for i in range(m):
    x,y=map(int,input().split())
    quant[x]-=1
    quant[y]+=1
    if prob[x]>0:
        prob[y]+=1
    if quant[x]==0:
        prob[x]=0

cnt=0
for i in range(n+1):
    if prob[i]>0:
        cnt+=1
print(cnt)

Solution (Python):
import numpy as np
import math

n, m = map(int, input().split())
probability = [0 for _ in range(n)]
ball = [1 for _ in range(n)]
probability[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    prob = math.ceil(probability[x-1])
    probability[x-1] = prob * (ball[x-1] - 1) / ball[x-1]
    probability[y-1] += prob / ball[x-1]
    ball[x-1] -= 1
    ball[y-1] += 1
print(np.sum(np.array(probability) > 0))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, M = MAP()
balls = [[1, 0] for _ in range(N)]  
balls[0] = [0, 1]

for _ in range(M):
	x, y = MAP()

	w_x, r_x = balls[x-1]
	w_y, r_y = balls[y-1]

	if w_x >= 1 and r_x >= 1: 
		balls[x-1][0] -= 1
		balls[y-1][1] += 1

	elif w_x == 0:
		balls[x-1][1] -= 1
		balls[y-1][1] += 1

	else:
		balls[x-1][0] -= 1
		balls[y-1][0] += 1

ans = 0
for i in range(N):
	if balls[i][1]:
		ans += 1
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, M = MAP()
xy = [LIST() for _ in range(M)]

check = [0]*N
check[0] = 1
cnt = [1]*N

for x, y in xy:
	if check[x-1]:
		check[y-1] = 1
	cnt[x-1] -= 1
	cnt[y-1] += 1
	if cnt[x-1] == 0:
		check[x-1] = 0

print(sum(check))

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())

red = [0]*N
red[0] = 1
box = [1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    if red[x] == 1 and box[x] == 1:
        
        red[x] -= 1
        red[y] = 1
    elif red[x] == 1 and box[x] >= 2:
        
        red[y] = 1
    box[x] -= 1
    box[y] += 1

print(red.count(1))

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())

red = [0]*N
red[0] = 1
box = [1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    if red[x] == 0:
        
        box[x] -= 1
        box[y] += 1
    elif red[x] == 1 and box[x] == 1:
        
        box[x] -= 1
        box[y] += 1
        red[x] -= 1
        red[y] = 1
    elif red[x] == 1 and box[x] >= 2:
        
        box[x] -= 1
        box[y] += 1
        red[y] = 1

print(red.count(1))