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())
stack = [1]*n
p = [False]*n
p[0] = True

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

ans = 0
for i in p:
    if i:
        ans += 1
print(ans)

Solution (Python):
N,M = (int(x) for x in input().split())
ball = [1 for x in range(N)]
red = [1] + [0 for x in range(N-1)]

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

print(N - sorted(red).index(1))

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

c = [1 for i in range(n)]
p = [0 for i in range(n)]
p[0]=1

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

print(p.count(1))

Solution (Python):

N, M = map(int, input().split())
moveList = [list(map(int, input().split())) for i in range(M)]
redFlag = [False for i in range(N)]
redFlag[0] = True
nums = [1 for i in range(N)]

for m in moveList:
    x, y = m[0]-1, m[1]-1
    
    nums[x] -= 1
    nums[y] += 1
    if redFlag[x]: redFlag[y] = True
    if (nums[x] == 0): redFlag[x] = False
    
print(sum(redFlag))

Solution (Python):

import sys


def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    balls = [1 for i in range(N)]
    red = [False for i in range(N)]
    red[0] = True

    for i in range(M):
        if red[x[i]]:
            if balls[x[i]] == 1:
                red[x[i]] = False
            red[y[i]] = True
        balls[x[i]] -= 1
        balls[y[i]] += 1
    
    print(sum(red))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    x = [int()] * (M)  
    y = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))-1
        y[i] = int(next(tokens))-1
    solve(N, M, x, y)

if __name__ == '__main__':
    main()

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

Solution (Python):

N, M = map(int, input().split())
x, y = zip(*(map(int, input().split()) for _ in range(M)))


c = [1 for _ in range(N + 1)]
r = [False for _ in range(N + 1)]
r[1] = True
for a, b in zip(x, y):
    c[b] += 1
    r[b] |= r[a]
    c[a] -= 1
    r[a] &= c[a] >= 1
ans = sum(r)


print(ans)

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

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

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

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

Solution (Python):
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

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

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)

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

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

Solution (Python):
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
ball = [1]*N
aka = [False]*N
aka[0] = True
for i in range(M):
  if aka[L[i][0]-1] == True:
    aka[L[i][1]-1] = True
  ball[L[i][0]-1] -= 1
  if ball[L[i][0]-1] == 0:
    aka[L[i][0]-1] = False
  ball[L[i][1]-1] += 1
ans = 0
for i in range(N):
  if aka[i] == True:
    ans += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
boxs=[1]*n
TF=[1]+[0]*(n-1)
for i in range(m):
    a,b=map(int,input().split())
    if boxs[a-1]==0:
        continue
    else:
        boxs[a-1]-=1
        boxs[b-1]+=1
    if TF[a-1]==1 and boxs[a-1]==0:
        TF[a-1]=0
        TF[b-1]=1
    elif TF[a-1]==1:
        TF[b-1]=1

print(sum(TF))

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from collections import Counter

def main():
    N, M = LI()
    XY = []
    for _ in range(M):
        XY.append(LI_())
    balls = [1] * N
    exp = set([0])
    for x, y in XY:
        balls[x] -= 1
        balls[y] += 1
        if x in exp:
            exp.add(y)
            if balls[x] == 0:
                exp.remove(x)
    ans = len(exp)
    return ans

print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from collections import Counter

def main():
    N, M = LI()
    XY = []
    for _ in range(M):
        XY.append(LI_())
    balls = [1] * N
    exp = set([0])
    for x, y in XY:
        balls[x] -= 1
        balls[y] += 1
        if x in exp:
            exp.add(y)
            if balls[x] == 0:
                exp.remove(x)
    ans = len(exp)
    return ans

print(main())

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

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

print(sum(1 for r in red if r))

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

ans = 0
for t in boolball:
    if t:
        ans += 1

print(ans)

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

red = [False] * N
box = [1] * N
red[0] = True

for i in range(M):
    x, y = items[i]
    x, y = x - 1, y - 1

    if box[x] and red[x]:
        red[y] = True

    if box[x] == 1 and red[x]:
        red[x] = False

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

print(red.count(True))

Solution (Python):
a,b = map(int, input().split())
n = [1]*a
r = [0]*a
r[0] = 1

for i in range(b):
    ta,tb = map(int, input().split())
    ta-=1
    tb-=1
    if r[ta] == 1:
        r[tb] = 1
    n[ta] -=1
    n[tb] +=1
    if n[ta] ==0:
        r[ta] = 0
print(sum(r))

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

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

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

Solution (Python):
N,M=list(map(int,input().split()))
W=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
BOX=[[1,1]]
BOX.extend([[1,0] for _ in range(N)])
for i in range(M):
    BOX[W[i][0]][0]=BOX[W[i][0]][0]-1
    BOX[W[i][1]][0]=BOX[W[i][1]][0]+1
    if(BOX[W[i][0]][1]==1):
        BOX[W[i][1]][1]=1
        if(BOX[W[i][0]][0]==0):
            BOX[W[i][0]][1]=0
print(sum(list(map(lambda x:x[:][1],BOX))))

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

Solution (Python):
n,m=map(int,input().split())
num=[1]*n
red=[True]+[False]*(n-1)
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 not num[x]:
        red[x]=False
print(sum(red))

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

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

x = [0 for i in range(M)]
y = [0 for j in range(M)]
for k in range(M):
    x[k],y[k] = map(int,input().split())
    x[k] -= 1
    y[k] -= 1

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

for i in range(M):
    ball[x[i]] -= 1
    ball[y[i]] += 1
    if red[x[i]] == 1:
        red[y[i]] = 1
    if ball[x[i]] == 0:
        red[x[i]] = 0

print(sum(red))

Solution (Python):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[False]*(N+1)
ans[1]=True
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if ans[x] and not ans[y]: 
    ans[y]=True
  if ans[x] and cnt[x]==0:
    ans[x]=False
print(sum(ans))

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

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

Solution (Python):


import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

    B = [1] * n
    R = [0] * n
    R[0] = 1

    for _ in range(m):
        x, y = LI_()

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

        
        if R[x]:
            R[y] = 1

        
        if not B[x]:
            R[x] = 0

    return sum(R)


print(main())

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
box = [1]*N
red = [False]*N
red[0] = True


def update(fr, to):
    if box[fr] == 1:
        red[to] = red[fr] | red[to]
        box[fr] -= 1
        red[fr] = False
        box[to] += 1
    else:
        red[to] = red[fr] | red[to]
        box[fr] -= 1
        box[to] += 1


for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    update(a, b)

ans = sum(red)
print(ans)

Solution (Python):
from collections import defaultdict


D = defaultdict(int)
d = defaultdict(lambda: 1)
D[1] = 1

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

for i in range(M):
	x, y = list(map(int, input().split()))
	if D[x] == 1:
		if d[x] == 1:
			D[x] = 0
		D[y] = 1

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

s = 0
for i in range(1, N + 1):
	if D[i] == 1:
		s += 1

print(s)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

n,m = getNM()

balls = [[1,0] for i in range(n)]
balls[0] = [1,1]
for i in range(m):
    x,y = getNM()
    x -= 1
    y -= 1
    balls[y][0] += 1
    if balls[x][1] == 1:
        balls[y][1] = 1
    balls[x][0] -= 1
    if balls[x][0] == 0:
        balls[x][1] = 0

print(sum([b[1] for b in balls]))

Solution (Python):
n,m = map(int,input().split())
num_ball =[1]*n
possible = [False]*n
possible[0]= True

for i in range(m):
  here,next = map(int,input().split())
  next -=1
  here -=1
  
  if possible[here]:
    possible[next]=True
    if num_ball[here] == 1:
      possible[here]=False
  else:
    if num_ball[here] == 1:
      possible[here]=False
      
  num_ball[here] -=1
  num_ball[next] +=1
  
print(possible.count(True))

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

Solution (Python):
N,M = map(int,input().split())
L = list(list(map(int,input().split())) for i in range(M))

A = [1 for i in range(N+1)]

red = [0 for i in range(N+1)]
red[1] = 1

ans = 1
for i in range(M) :
    A[L[i][0]] -= 1
    A[L[i][1]] += 1
    if red[L[i][0]] == 1 :
        red[L[i][1]] = 1
    if A[L[i][0]] == 0 :
        red[L[i][0]] = 0
        
ans = sum(red)
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ball = [1]*n
inred = [0]*n
inred[0] = 1

for _ in range(m):
    x,y = li_()
    if inred[x] and ball[x] == 1:
        inred[x] = 0
        ball[x] = 0
        
        inred[y] = 1
        ball[y] += 1
        
    elif inred[x] and ball[x] > 1:
        ball[x] -= 1
        
        inred[y] = 1
        ball[y] += 1
        
    else:
        ball[x] -= 1
        ball[y] += 1
        
ans = 0
for ri in inred:
    ans += ri
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ball = [1]*n
inred = [0]*n
inred[0] = 1

for _ in range(m):
    x,y = li_()
    if inred[x] and ball[x] == 1:
        inred[x] = 0
        ball[x] = 0
        
        inred[y] = 1
        ball[y] += 1
        
    elif inred[x] and ball[x] > 1:
        ball[x] -= 1
        
        inred[y] = 1
        ball[y] += 1
        
    else:
        ball[x] -= 1
        ball[y] += 1
        
ans = 0
for ri in inred:
    ans += ri
print(ans)

Solution (Python):
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
red = [0] * N
red[0] = 1
ballnum = [1] * N

for a,b in src:
    a,b = a-1,b-1
    ballnum[b] += 1
    ballnum[a] -= 1
    if red[a]:
        red[b] = 1
        if not ballnum[a]:
            red[a] = 0
print(sum(red))

Solution (Python):
N,M = map(int,input().split())
L = list(list(map(int,input().split())) for i in range(M))

A = [1 for i in range(N+1)]

red = [0 for i in range(N+1)]
red[1] = 1

ans = 1
for i in range(M) :
    A[L[i][0]] -= 1
    A[L[i][1]] += 1
    if red[L[i][0]] == 1 :
        red[L[i][1]] = 1
    if A[L[i][0]] == 0 :
        red[L[i][0]] = 0
        
ans = sum(red)
print(ans)

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

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

box = [1] * n
color = [0] * n
color[0] = 1

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

print(sum(color))

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

Solution (Python):
n, m = map(int, input().split())
c = []
for i in range(m):
    c.append([int(m) for m in input().split()])
ball = []
for i in range(n + 1):
    if i == 1:
        ball.append([1, 1])
    else:
        ball.append([0, 1])
for i in range(m):
    if ball[c[i][0]][0] == 0:
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
    elif ball[c[i][0]][1] == 1:
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
        ball[c[i][1]][0] = 1
        ball[c[i][0]][0] -= 1
    else:
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
        ball[c[i][1]][0] = 1

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

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

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

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

for x, y in XY:
    num[x] -= 1
    num[y] += 1
    if red[x] == True:
        red[y] = True
        if num[x] == 0:
            red[x] = False
print(sum(red))

Solution (Python):
N,M = map(int,input().split())
xy = []
for _ in range(M):
    xy.append(list(map(int,input().split())))
    xy[-1][0] -= 1
    xy[-1][1] -= 1
redp = [[False,1] for _ in range(N)]
redp[0] = [True,1]
for x,y in xy:
    if redp[x][0]:
        if redp[x][1] == 1:
            redp[x][0] = False
            redp[x][1] = 0
            redp[y][0] = True
            redp[y][1] += 1
        else:
            redp[x][1] -= 1
            redp[y][0] = True
            redp[y][1] += 1
    else:
        redp[x][1] -= 1
        redp[y][1] += 1


count = 0
for i in redp:
    if i[0]:
        count += 1
print(count)

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

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

Solution (Python):
n, m = map(int,input().split())
f = [False for _ in range(n)]
c = [1 for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().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
ans = 0
for i in range(n):
  if f[i] and c[i] > 0:
    ans += 1
print(ans)

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

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

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

for i in range(m):
    if r[x[i]] == True:
        r[y[i]] = True
    num[x[i]] -= 1
    num[y[i]] += 1
    
    if num[x[i]] == 0:
        r[x[i]] = False

print(r.count(True))

Solution (Python):
N,M=map(int,input().split())
table=[]
for i in range(M):
    x,y=map(int,input().split())
    table.append((x-1,y-1))
F=[False]*N
F[0]=True
L=[1]*N
for x,y in table:
    L[x]-=1
    L[y]+=1
    if F[x]:
        F[y]=True
    if L[x]==0:
        F[x]=False
    
    
print(sum(F))

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

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

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

ball_list = [1 for i in range(N)]
flag_list = [False for i in range(N)]
flag_list[0] = True

for i in range(M):
    x,y = list(map(int,input().split()))
    if flag_list[x-1]:
        flag_list[y-1]=True
        if ball_list[x-1]==1:
            flag_list[x-1]=False
    ball_list[x-1]-=1
    ball_list[y-1]+=1
count=0    
for i in range(N):
    if flag_list[i]:
        count+=1

print(count)

Solution (Python):

import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    is_red = [False for i in range(N+1)]
    is_red[1] = True
    ball_num = [1 for i in range(N+1)]
    for i in range(M):
        input_raw = read_func().strip().split()
        [x, y] = [long(input_raw[0]), long(input_raw[1])]
        ball_num[x] -= 1
        ball_num[y] += 1
        if is_red[x] == True:
            is_red[y] = True
        if ball_num[x] == 0:
            is_red[x] = False

    print sum(is_red)

if __name__ == '__main__':
    main()

Solution (Python):
N,M = (int(i) for i in input().split())  

class Box:
      def __init__(self):
         self.ball = 1
         self.pos = False
box = [] 
for i in range(N):
    box.append(Box())
box[0].pos = True

for i in range(M):
    x,y = (int(i) for i in input().split())  
    if box[x - 1].pos:
       box[y - 1].pos = True
    box[x - 1].ball -= 1
    box[y - 1].ball += 1
    if box[x - 1].ball == 0:
       box[x - 1].pos = False
cnt = 0;
for i in range(N):
   if box[i].pos:
      cnt += 1
print(cnt)

Solution (Python):

n,m = map(int, input().split())
s = set([1])
d = {}
d[1] = 1

for _ in range(m):
    x,y = map(int, input().split())
    if x not in d:
        d[x] = 0
    else:
        d[x] -= 1
    if y not in d:
        d[y] = 2
    else:
        d[y] += 1
    if x in s:
        if x in d and d[x]==0:
            s.remove(x)
        s.add(y)


print(len(s))

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def operation(box:list, frm:int, to:int):
    box[frm] -= 1
    box[to] += 1
    
n,m = li()
box = [1 for _ in range(n)]
cand = [False for _ in range(n)]
cand[0] = True
ope = []
for _ in range(m):
    x,y = li_()
    ope.append((x,y))
    
for x,y in ope:
    operation(box,x,y)
    if (not cand[y]) and cand[x]:
        cand[y] = True
    
    if cand[x] and box[x] > 0:
        cand[x] = True
        
    elif cand[x] and box[x] == 0:
        cand[x] = False
        
print(sum(cand))

Solution (Python):
N,M=map(int,input().split())
grid = []
for i in range(M):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
nums = []
judge = []
while len(nums)<N:
  nums.append(1)
  judge.append(False)
judge[0] = True
for arrays in grid:
  if judge[arrays[0]-1] == True:
    judge[arrays[1]-1] = True
  nums[arrays[0]-1] += -1
  nums[arrays[1]-1] += 1
  if nums[arrays[0]-1]==0:
    judge[arrays[0]-1] = False
ans = 0
for states in judge:
  if states == True:
    ans += 1
print(ans)

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

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

Q = [] 
for i in range(M):
  Q.append(list(map(int,input().split())))

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

Red[0] = 1

for i in range(M):
  x, y = Q[i]
  x, y = x-1, y-1 
  Count[x] -= 1
  Count[y] += 1
  if Red[x] == 1:
    Red[y] = 1
  if Count[x] == 0:
    Red[x] = 0
    
print(sum(Red))

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

Solution (Python):
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]|=l[x];c[y]+=1;c[x]-=1;l[x]=c[x]and l[x]
print(sum(c[i]and l[i]for i in range(n+1)))

Solution (Python):
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]|=l[x];c[y]+=1;c[x]-=1;l[x]=c[x]and l[x]
print(sum(c[i]and l[i]for i in range(n+1)))

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

Solution (Python):
N,M=map(int,input().split())
list1=[["w",1]for i in range(N+1)]
list1[0]=[0,0]
list1[1]=["r",1]

for j in range(M):
    x,y=map(int,input().split())
    list1[x][1]-=1
    list1[y][1]+=1
    if list1[x][0]=="r":
        list1[y][0]="r"
        if list1[x][1]==0:
            list1[x][0]="w"
cnt=0
for k in range(1,N+1):
    if list1[k][0]=="r":
        cnt+=1
print(cnt)

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

count = [1 for i in range(n)]
possible = [0 for i in range(n)]
possible[0] = 1

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

ans = 0
for i in range(n):
    ans += possible[i]
print(ans)

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

exist = [False for i in range(n)]
counts = [1 for i in range(n)]
exist[0] = True

for i in range(m):
    counts[procedure[i][0]] += -1
    counts[procedure[i][1]] += 1
    if exist[procedure[i][0]]:
        exist[procedure[i][1]] = True
    if counts[procedure[i][0]] == 0:
        exist[procedure[i][0]] = False

counter = 0
for i in range(n):
    if exist[i]:
        counter += 1

print(counter)

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

print(sum(red))

Solution (Python):
import sys
N, M = map(int, input().split())
num = [1] * (N + 1)
red = [0] * (N + 1)
red[1] = 1
for e in sys.stdin:
    x, y = map(int, e.split())
    if red[x]:
        red[y] = 1
    num[y] += 1
    num[x] -= 1
    if num[x] == 0:
        red[x] = 0
print(sum(red))

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, M = inpl()


ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]

for i in range(M):
    
    x, y = inpl()
    box[x - 1] -= 1
    box[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if box[x - 1] == 0:
            ans[x - 1] = 0
    


print(sum(ans))