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):
N, M = map(int, input().split())
box = [1] * N
red = [1]
red.extend([0] * (N - 1))

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


print(sum(red))

Solution (Python):
import numpy as np
n, m = map(int, input().split())
'''
xx = []
yy = []
'''
box = np.zeros((n, 2))
box[:, 0] = 1
box[0, 1] = 1


count = 0
for _ in range(m):
    x, y = map(int, input().split())
    '''
    xx.append(x)
    yy.append(y)
    '''
    if (box[x - 1, 1] == 1):
        box[y - 1, 1] = 1

    box[x - 1, 0] -= 1

    if (box[x - 1, 0] == 0):
        box[x - 1, 1] = 0

    box[y - 1, 0] += 1

    
tar = box[:, 1]
ans = np.sum(tar != 0)
print(ans)

Solution (Python):
(N, M), *AB = [map(int, s.split()) for s in open(0)]
cnt = [1] * N
possibly_red = [False] * N
possibly_red[0] = True
for a, b in AB:
    a -= 1
    b -= 1
    cnt[a] -= 1
    cnt[b] += 1
    if possibly_red[a]:
        possibly_red[b] = True
        if cnt[a] == 0:
            possibly_red[a] = False
print(sum(possibly_red))

Solution (Python):
n, m = map(int, input().split())
rednow = [-1, 1] + [0 for i in range(n-1)] 
balnum = [-1] + [1 for i in range(n)] 
order = []
for i in range(m):
  order.append(list(map(int, input().split()))) 

for q in order:
  if rednow[q[0]] == 1:
    rednow[q[1]] = 1
    if balnum[q[0]] == 1:
      rednow[q[0]] = 0
  balnum[q[0]] -= 1
  balnum[q[1]] += 1

print(rednow.count(1))

Solution (Python):
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
B = [1] * N
possible = {0}
for i in range(M):
  x,y = map(int,readline().split())
  x,y = x - 1,y - 1
  B[x] -= 1
  B[y] += 1
  if x in possible:
    possible.add(y)
  if x in possible and B[x] == 0:
    possible.remove(x)

print(len(possible))

Solution (Python):
N, M = map(int,input().split())
red = [0] * N
red[0] = 1
boal = [1] * N

for i in range(M):
    x, y = map(int,input().split())
    x -= 1
    y -= 1
    if red[x] == 1 and boal[x] == 1:
        red[x] = 0
        boal[x] -= 1
        red[y] = 1
        boal[y] += 1
    elif red[x] == 1 and boal[x] > 1:
        boal[x] -= 1
        red[y] = 1
        boal[y] += 1
    else:
        boal[x] -= 1
        boal[y] += 1
print(sum(red))

Solution (Python):

"""
Created on Sun Jun  7 14:28:00 2020

@author: NEC-PCuser
"""

N, M = map(int, input().split())
x, y = [], []

for i in range(M):
    x_tmp, y_tmp = map(int, input().split())
    x.append(x_tmp)
    y.append(y_tmp)

box = [1] * N 
ball_set = set()
ball_set.add(1)
start_flg = True
for i in range(len(x)):
    if x[i] in ball_set:
        ball_set.add(y[i])
    box[x[i] - 1] -= 1
    box[y[i] - 1] += 1
    if box[x[i] - 1] == 0:
        ball_set.discard(x[i])

print(len(ball_set))

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

ans = possibility.count(True)
print(ans)

Solution (Python):
N,M = list(map(int,input().split()))
XY = [list(map(int,input().split())) for _ in range(M)]
L1 = [1]*N
L2 = [0]*N
L2[0] = 1
for xy in XY:
    if L2[xy[0]-1] == 1:
        L2[xy[1]-1] = 1
    L1[xy[0]-1] -= 1
    L1[xy[1]-1] += 1
    if L1[xy[0]-1] == 0:
        L2[xy[0]-1] = 0
print(sum(L2))

Solution (Python):

N,M = map(int,input().split())
move = [list(map(int,input().split())) for _ in range(M)]
box = [[1,0] for _ in range(N+1)]
box[1][1] = 1
for x,y in move:
    box[x][0] -= 1
    box[y][0] += 1
    if box[x][1]==1:
        box[y][1] = 1
        if box[x][0]==0:
            box[x][1] = 0
print(sum(b[1] for b in box))

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

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

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

c = [1]*N
r = [0]*N
r[0] = 1

for _ in range(M):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    if r[x]:
        if c[x] == 1:
            r[x] = 0
        r[y] = 1
    c[x] -= 1
    c[y] += 1

print(sum(r))

Solution (Python):
def main():
    n, m = list(map(int, input().split()))
    ans = set([1, ])
    balls = [1] * n
    for _ in range(m):
        x, y = list(map(int, input().split()))
        if x in ans:
            ans.add(y)
        if balls[x - 1] == 1 and x in ans:
            ans.remove(x)
        balls[x - 1] -= 1
        balls[y - 1] += 1
    print(len(ans))

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    f = [False] * N
    c = [1] * N
    f[0] = True
    
    for m in range(M):
        x, y = [int(x) for x in input().strip().split()]
        f[y-1] = f[y-1] or f[x-1]
        c[y-1] += 1
        c[x-1] -= 1
        if c[x-1] == 0:
            f[x-1] = False
        
    print(len([1 for b in f if b]))

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
X, Y = [], []
d = {n:1 for n in range(N)}
r = set([0])
for _ in range(M):
    x, y = map(int, input().split())
    d[x-1] -= 1
    d[y-1] += 1
    if x - 1 in r:
        r.add(y - 1)
        if d[x - 1] == 0:
            r.remove(x - 1)
    X.append(x)
    Y.append(y)

print(len(r))

Solution (Python):
import numpy as np   
n,m = [int(i)for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

line = np.array([1 for _ in range(n)])
is_red = np.zeros(n,dtype = np.int32)
is_red[0] = 1

for x,y in l:
    line[x] -= 1 if line[x] > 0 else 0
    line[y] += 1
    is_red[y] = 1 if is_red[x] == 1 else is_red[y]
    is_red[x] = is_red[x] if line[x] > 0 else 0
    

ans = np.count_nonzero(is_red[line > 0])

print(ans)

Solution (Python):
import numpy as np

n,m = map(int,input().split())
l = []
for _ in range(m):
    a = list(map(int,input().split()))
    l.append(a)

memo = np.zeros((n,2))
memo[0][1] = 1

for i in range(n):
    memo[i][0] = 1

tmp1 = 0
tmp2 = 0

for j in range(m):
    tmp1 = l[j][0]-1
    tmp2 = l[j][1]-1
    memo[tmp1][0] -= 1
    memo[tmp2][0] += 1
    
    if memo[tmp2][1] == 0 and memo[tmp1][1] == 1:
        memo[tmp2][1] = 1
    
    if memo[tmp1][1] == 1 and memo[tmp1][0] == 0:
        memo[tmp1][1] = 0

ans = 0
for k in range(n):
    ans += memo[k][1]

print(int(ans))

Solution (Python):
N, M = map(int, input().split())
X = [0] * (M)
Y = [0] * (M)

started = False
contains_red = set([1])
ans = 1

nums = [1] * (N + 1)

for _ in range(M):
    x, y = map(int, input().split())
    X[_] = x
    Y[_] = y

for _ in range(M):
    nums[X[_]] -= 1
    nums[Y[_]] += 1

    if X[_] in contains_red:
        contains_red.add(Y[_])

    if nums[X[_]] == 0 and X[_] in contains_red:
        contains_red.remove(X[_])


print(len(contains_red))

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

R = [0 for _ in range(N+1)] 
C = [1 for _ in range(N+1)] 
R[1] = 1


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


print(R.count(1))

Solution (Python):
n,m = map(int,input().split())
ball = [1]*n
ans = [0]*n
ans[0] = 1

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

a = 0
for an in ans:
    if an == 1:
        a += 1

print(a)

Solution (Python):
N, M = map(int, input().split())
XYs = [list(map(int, input().split())) for _ in range(M)]

flag = [0]*(N+1)
flag2 = [0]*(N+1)
flag[1] = 1
flag2[1] = 1
num = [1]*(N+1)

for xy in XYs:
  if flag2[xy[0]]==1 and flag[xy[0]]==1:
    flag[xy[0]]=0
    flag[xy[1]]=1
  elif flag[xy[0]]==1:
    flag[xy[1]]=1
  
  if flag2[xy[0]]==1 and num[xy[1]] == 0:
    flag2[xy[0]]=0
    flag2[xy[1]]=1
  else:
    flag2[xy[0]]=0
    flag2[xy[1]]=0
  num[xy[0]] -= 1
  num[xy[1]] += 1
  if num[xy[0]] == 0:
    flag[xy[0]] = 0
  
print(sum(flag))

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    if s[x-1]:
        s[y-1] = 1
    if b[x-1] == 1:
        s[x-1] = 0
    b[x-1] -= 1
    b[y-1] += 1

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

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

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(1)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: 
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

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

red = [False]*n
red[0] = True
balls = [1]*n

for x, y in mat:
    x -= 1
    y -= 1
    if red[x] is True:
        red[y] = True
    balls[x] -= 1
    balls[y] += 1
    if balls[x] == 0:
        red[x] = False

ans = 0
for r in red:
    if r is True:
        ans += 1
print(ans)

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

box = [1] * (n+1) 
redbox = [False] * (n+1) 
redbox[1] = True
for _ in range(m):
    x,y = list(map(int, input().split()))
    box[x]-=1
    box[y]+=1
    if redbox[x]:
        redbox[y] = True
    if box[x]==0:
        redbox[x] = False


print(sum(map(int, redbox[1:])))

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

Solution (Python):
n,m = [int(x) for x in input().split()]
xy = []
for _ in range(m):
    tmp = [int(x)-1 for x in input().split()]
    xy.append(tmp)

box = {x: 1 for x in range(n)}
red = {x: False for x in range(n)}
red[0] = True

for x,y in xy:
    box[x] -= 1
    box[y] += 1
    if red[x]:
        red[y] = True
    if box[x] == 0:
        red[x] = False

print(len([1 for x in red.values() if x]))

Solution (Python):
def main():
    N,M  = map(int,(input().split()))
    BOX = [0]+[1]*N
    RED = [False]*(N+1)
    RED[1] = True

    for _ in range(M):
        x,y = map(int,(input().split()))
        BOX[x] -=1
        BOX[y] +=1
        if RED[x]:
            RED[y]=True
        if BOX[x]==0:
            RED[x]=False
    cnt = 0
    for r in RED:
        if r:
            cnt +=1
    print(cnt)



if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
C = [1]*n
X = [0]*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:
        C[x] -= 1
        C[y] += 1
        X[y] = 1
        if C[x] == 0:
            X[x] = 0
    else:
        C[x] -= 1
        C[y] += 1


print(sum(X))

Solution (Python):
n, m = map(int, input().split())
C = [1]*n
X = [0]*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:
        C[x] -= 1
        C[y] += 1
        X[y] = 1
        if C[x] == 0:
            X[x] = 0
    else:
        C[x] -= 1
        C[y] += 1


print(sum(X))

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

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

a = [[1, False] for _ in range(n+1)]
a[1] = [1, True]

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

print(sum(x[1] for x in a))

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


b = [1] * n
red = [1] + [0] * (n - 1)

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

    
    if red[x - 1] == 1:
        red[y - 1] = 1

    
    b[x - 1] -= 1
    b[y - 1] += 1

    
    if b[x - 1] == 0:
        red[x - 1] = 0

ans = len([x for x in red if x > 0])

print(ans)

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


b = [1] * n
red = [1] + [0] * (n - 1)

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

    
    if red[x - 1] == 1:
        red[y - 1] = 1

    
    b[x - 1] -= 1
    b[y - 1] += 1

    
    if b[x - 1] == 0:
        red[x - 1] = 0

ans = len([x * y for x, y in zip(b, red) if x * y > 0])

print(ans)

Solution (Python):
N,M= list(map(int,input().split()))
dot=[1]*N
sw=[0] * N
sw[0]=1
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   dot[a]-=1
   dot[b]+=1
   if sw[a]:
      sw[b]=1
   if dot[a] == 0:
      sw[a]=0
print(sw.count(1))

Solution (Python):
n,m=map(int,input().split())
ans=[0 for _ in range(n+1)]
cnt=[1 for _ in range(n+1)]
ans[1]=1
for i in range(m):
  a,b=map(int,input().split())
  if ans[a]==1:
    ans[b]=1
    if cnt[a]==1:
      ans[a]=0
  cnt[a]-=1
  cnt[b]+=1
print(sum(ans))

Solution (Python):
n, m = map(int, input().split())
checker = [1 for _i in range(n+1)]
r = [0 for i in range(n+1)]
r[1] = 1
for _i in range(m):
    x, y = map(int, input().split())
    checker[x] -= 1
    checker[y] += 1
    if r[x]>0:
        r[y] = 1
    if (r[x]>0) and (checker[x]==0):
        r[x] = 0
print(sum(r))

Solution (Python):
n, m = map(int, input().split())
checker = [1 for _i in range(n+1)]
r = [0 for i in range(n+1)]
r[1] = 1
for _i in range(m):
    x, y = map(int, input().split())
    checker[x] -= 1
    checker[y] += 1
    if r[x]>0:
        r[y] = 1
    if (r[x]>0) and (checker[x]==0):
        r[x] = 0
print(sum(r))

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,*xy = map(int, read().split())

    check = [False] * N
    check[0] = True
    num = [1] * N

    for x, y in zip(*[iter(xy)]*2):
        num[x-1] -= 1
        num[y-1] += 1
        if check[x-1]:
            check[y-1] = True
        if num[x-1] == 0:
            check[x-1] = False

    ans = sum(check)
    print(ans)


if __name__ == "__main__":
    main()

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

exist = [0] * n
exist[0] = 1
cnt = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    if exist[x - 1] == 1:
        exist[y - 1] = 1
        if cnt[x - 1] == 1:
            exist[x - 1] = 0

    
    cnt[x - 1] -= 1
    cnt[y - 1] += 1
print(sum(exist))

Solution (Python):


n, m = map(int, input().split())

b_list = [0] * (n+1)
b_list[1] = 1
c_list = [1] * (n+1)

for i in range(m):
    _x, _y = map(int, input().split())
    c_list[_x] -= 1
    c_list[_y] += 1 
    if b_list[_x] == 1:
        b_list[_y] = 1
        if c_list[_x] == 0:
            b_list[_x] = 0

print(sum(b_list))

Solution (Python):
import sys

N,M=map(int,input().split())
ope=[]
for i in range(M):
    ope.append(tuple(map(int,input().split())))

state=[1]*N
red=[0]*N
red[0]=1
for i in range(M):
    x,y=ope[i]
    if red[x-1]:
        if state[x-1]>1:
            red[x-1]=1
            red[y-1]=1
        else:
            red[x-1]=0
            red[y-1]=1
    state[x-1]-=1
    state[y-1]+=1

print(sum(red))

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

Solution (Python):
N, M = map(int, input().split())
num = [1] * N
possible = [False] * N
possible[0] = True

for i in range(M):
  x, y = map(int, input().split())
  x -= 1; y -= 1
  nx, ny = num[x], num[y]
  if possible[x]:
    possible[y] = True
    if nx == 1:
      possible[x] = False
  
  num[x] -= 1; num[y] += 1

print(sum(possible))

Solution (Python):
n,m=map(int,input().split())
kosuu=[0]+[1]*n
haitteru=[0]+[1]+[0]*(n-1)
for _ in range(m):
    x,y=map(int,input().split())
    if haitteru[x]==1:
        kosuu[x]-=1
        kosuu[y]+=1
        haitteru[y]=1
        if kosuu[x]==0:
            haitteru[x]=0
    else:
        kosuu[x]-=1
        kosuu[y]+=1
print(haitteru.count(1))

Solution (Python):
def solve():
    N, M = map(int, input().split())
    
    num = []
    red = []
    for i in range(N+1):
        num.append(1)
        red.append(0)
    red[1] = 1
    
    for _ in range(M):
        x, y = map(int, input().split())
        if red[x] == 1:
            red[y] = 1
        num[x] -= 1
        num[y] += 1
        if num[x] == 0:
            red[x] = 0
    
    return sum(red)

print(solve())

Solution (Python):
n, m = map(int, input().split())
cl = [1 for _ in range(n)]
rl = [1]+[0 for _ in range(n-1)]

for i in range(m):
    x_n, y_n = map(int, input().split())
    cl[x_n-1] -= 1
    cl[y_n-1] += 1
    if rl[x_n-1] == 1 and cl[x_n-1]>0:
        rl[y_n-1] = 1
    elif rl[x_n-1] == 1 and cl[x_n-1] == 0:
        rl[x_n-1] = 0
        rl[y_n-1] = 1
    elif rl[x_n-1] == 0:
        pass
print(sum(rl))

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

ball_count = [1]*N
visited = [0]*N
visited[0] = 1

for x,y in xy:
  ball_count[x-1] -= 1
  ball_count[y-1] += 1
  if visited[x-1] == 1:
    visited[y-1] = 1
  if ball_count[x-1] == 0:
    visited[x-1] = 0

print(sum(visited))

Solution (Python):
N, M = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(M)]

"""
ボールの数が入ったリストと，赤い玉が一回でもきたことがあるかのリスト
どちらもが０じゃないのが，終わったときに赤が入っている可能性のあるリスト
ただし，ボールリストが０になる時，seenは０になる
"""
ball_list = [1] * (N+1)
seen = [0] * (N+1)
ball_list[0] = 0
seen[1] = 1

for i in range(M):
    x = XY[i][0]
    y = XY[i][1]
    if seen[x] == 1:
        seen[y] = 1
        ball_list[x] -= 1
        ball_list[y] += 1
        if ball_list[x] == 0:
            seen[x] = 0
    else:
        ball_list[x] -= 1
        ball_list[y] += 1

print(seen.count(1))

Solution (Python):
import copy
N,M = [int(hoge) for hoge in input().split()]
Ball = [False]*N
BallNum = [1] * N
Ball[0] = True
for i in range(M):
    x,y = [int(hoge) - 1  for hoge in input().split()]
    BallNum[x] -= 1
    BallNum[y] += 1
    if Ball[x]:
        Ball[y] = True 
    if BallNum[x] == 0:
        Ball[x] = False
print(sum(Ball))

Solution (Python):
n, m = map(int,input().split())
box = [[1,0] for i in range(n)]
box[0][1] = 1
ans = 1

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


print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
ans = [0 for _ in range(n)]
bal = [1 for _ in range(n)]
ans[0] = 1
for _ in range(m):
    x, y = MAP()
    bal[x - 1] -= 1
    bal[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if not bal[x - 1]:
            ans[x - 1] = 0
print(sum(ans))

Solution (Python):
def int_(num_str):
    return int(num_str) - 1

N, M = map(int, input().split())
balls = [1] * N
red = {0}
for i in range(M):
    x, y = map(int_, input().split())
    if x in red:
        if balls[x] == 1:
            red.remove(x)
            red.add(y)
        else:
            red.add(y)
    balls[x] -= 1
    balls[y] += 1
print(len(red))

Solution (Python):
n,m = map(int,input().split())
data = [[0,1] for i in range(n)]
data[0] = [1,1]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data[b][1] += 1
    data[a][1] -= 1
    if data[a][0] == 1:
        data[b][0] = 1
    if data[a][1] == 0:
        data[a][0] = 0
else:
    ans = 0
    for i in data:
        if i[0] == 1:
            ans += 1
    else:
        print(ans)

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

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    l[x] -= 1
    l[y] += 1
    r[y] = r[x] | r[y]
    if not l[x]:
        r[x] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)

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

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1
    r[y - 1] = r[x - 1] | r[y - 1]
    if not l[x - 1]:
        r[x - 1] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)

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

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1
    
    
    r[y - 1] = r[x - 1] | r[y - 1]
    if l[x - 1] == 0:
        r[x - 1] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)

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

r = [False] * n
r[0] = True
l = [1] * n

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

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)

Solution (Python):
n,m = map(int,input().split())
x_li = [0]*m
y_li = [0]*m
for i in range(m):
    x_li[i],y_li[i]=map(int,input().split())

map_li = [1]*n
red = [False]*n
red[0]=True

for i in range(m):
    x,y = x_li[i],y_li[i]
    x,y = x-1,y-1
    if red[x]:
        red[y]=True
    map_li[x]-=1
    map_li[y]+=1
    if map_li[x]==0:
        red[x]=False

print(sum(red))

Solution (Python):
n,m = map(int,input().split())
x_li = [0]*m
y_li = [0]*m
for i in range(m):
    x_li[i],y_li[i]=map(int,input().split())

map_li = [1]*n
red = [False]*n
red[0]=True

for i in range(m):
    x,y = x_li[i],y_li[i]
    x,y = x-1,y-1
    if red[x] and map_li[x]>1:
        red[y]=True
    elif red[x]:
        red[y]=True
        red[x]=False
    map_li[x]-=1
    map_li[y]+=1

print(sum(red))

Solution (Python):
n, m = map(int, input().split())
used = [False] * (n+1)
ball = [1] * (n+1)
used[1] = True
for _ in range(m):
    x,y = map(int, input().split())
    ball[x] -= 1
    ball[y] += 1
    if used[x]:
        used[y] = True
    if ball[x] == 0:
        used[x] = False
res = 0
for i in range(1, n + 1):
    if used[i] and ball[i] != 0:
        res += 1
print(res)

Solution (Python):
n , m = map(int,input().split())
aka = [False for i in range(n+1)]
kazu = [1 for i in range(n+1)]
aka[1] = True
for i in range(m):
    x , y = map(int,input().split())
    if aka[x]:
        if kazu[x] >= 2:
            kazu[x] -= 1
            kazu[y] += 1
        elif kazu[x] == 1:
            kazu[x] -= 1
            kazu[y] += 1            
            aka[x] = False
        aka[y] = True
    elif not aka[x]:
        kazu[x] -= 1
        kazu[y] += 1
ans = 0
for i in range(1,n+1):
    if aka[i]:
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(M)]

status = [False]*N
status[0] = True
ball = [1]*N

for x, y in XY:
  x, y = x-1, y-1
  ball[x] -= 1
  ball[y] += 1
  if status[x]:
    status[y] = True
  if status[x] and ball[x] == 0:
    status[x] = False

print(sum(status))

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

lisN = [0] + [1]*N
ansSet = set([1])

for _ in range(M):
    
    x,y = map(int,input().split())
    if x in ansSet:
        ansSet.add(y)
    lisN[x] -= 1
    lisN[y] += 1
    if lisN[x] == 0:
        ansSet.discard(x)

print(len(ansSet))

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
hako = [1]*(n+1)
iro = ['white']*(n+1)
iro[1] = 'red'

for _ in range(m):
    
    x,y = map(int,input().split())
    if iro[x] == 'red':
        iro[y] ='red'
    elif iro[x] == 'white' and hako[y] == 0:
        iro[y] = 'white'
    hako[x] -= 1
    hako[y] += 1
ans = 0
for i in range(1,n+1):
    if hako[i] > 0 and iro[i] == 'red':
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
boxes = [[0, 1] for _ in range(n)]
boxes[0][0] = 1
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    boxes[x][1] -= 1
    boxes[y][1] += 1
    if boxes[x][0] == 1:
        boxes[y][0] = 1
    else:
        if boxes[y][0] == 1:
            continue
        else:
            boxes[y][0] = 0  
    if boxes[x][1] == 0:
        boxes[x][0] = -1
ans = 0
for a, b in boxes:
    
    if a > 0:
        ans += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
xy = []
for _ in range(m):
    x, y = map(int, input().split())
    xy.append((x, y))
reds = [False]*n
reds[0] = True
balls = [1]*n
for x, y in xy:
    if reds[x-1] and balls[x-1]>1:
        reds[y-1] = True
    elif reds[x-1]:
        reds[y-1] = True
        reds[x-1] = False
    balls[x-1] -= 1
    balls[y-1] += 1
print(sum(reds))

Solution (Python):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    R = [0]*(N)
    W = [1]*(N)
    R[0] = 1
    W[0] = 0
    for _ in range(M):
        x, y = map(int, readline().split())
        if R[x-1]==1 and W[x-1]>=1:
            W[x-1] -= 1
            if R[y-1]==0:
                R[y-1]+=1
            else:
                W[y-1]+=1
        elif R[x-1]==0 and W[x-1]>=1:
            W[x-1] -= 1
            W[y-1] += 1
        else:
            R[x-1] -= 1
            R[y-1] += 1
    ans = 0
    for i in range(N):
        if R[i]>=1:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))



def main():
    n, m = ns()

    table_TF = [False for _ in range(n)]
    table_TF[0] = True

    table_cnt = [1 for _ in range(n)]

    for _ in range(m):
        x, y = ns()
        x -= 1
        y -= 1

        table_cnt[x] -= 1
        table_cnt[y] += 1
        if table_TF[x]:
            table_TF[y] = True
        if table_cnt[x] == 0:
            table_TF[x] = False

    ans = 0
    for tf in table_TF:
        if tf:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def mov(xy,N):
    Box_red = set([1])
    Box = [1 for _ in range(N)]

    for i in range(len(xy)):
        Box[xy[i][0]-1] -= 1
        Box[xy[i][1]-1] += 1
        if xy[i][0] in Box_red:
            Box_red.add(xy[i][1])
        if Box[xy[i][0]-1] == 0:
            Box_red.discard(xy[i][0])

    return len(Box_red)

def main():
    N,M = map(int,input().split())
    xy = [list(map(int,input().split())) for _ in range(M)]
    ans = mov(xy,N)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n, m = MI()

    B = [1] * n
    J = [False] * n
    J[0] = True

    for i in range(m):
        x, y = MI1()

        if J[x] == True:
            if B[x] == 1:
                J[x] = False
            B[x] -= 1
            J[y] = True
            B[y] += 1
        else:
            if B[x] > 0:
                B[x] -= 1
                B[y] += 1
    print(sum(J))





if __name__ == '__main__':
    solve()