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):
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, M = readnums()
    xy = [tuple(readnums()) for _ in range(M)]
    dic = {i: 1 for i in range(1, N + 1)}
    r = {1}
    for (x, y) in xy:
        dic[x] -= 1
        dic[y] += 1
        if x in r:
            r.add(y)
            if not dic[x]:
                r.remove(x)

    print(len(r))


if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
kosu = [1 for _ in range(n)]
aka = [0 for _ in range(n)]
aka[0] += 1
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  if aka[a]==1:
    
    aka[b] |= 1
    if kosu[a]<2:
      aka[a] -=1
  kosu[a] -=1
  kosu[b] += 1
 
  
print(aka.count(1))

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

red_boxes = [False for i in range(n)]
red_boxes[0] = True
n_ball = [1 for i in range(n)]


for i in range(m):
    x_i = xy[i][0]-1
    y_i = xy[i][1]-1
    
    if n_ball[x_i] == 1:
        if red_boxes[x_i] == True:
            n_ball[x_i] -= 1
            n_ball[y_i] += 1
            red_boxes[x_i] = False
            red_boxes[y_i] = True
        
        else:
            n_ball[x_i] -= 1
            n_ball[y_i] += 1
    
    else:
        if red_boxes[x_i] == True:
            n_ball[x_i] -= 1
            n_ball[y_i] += 1
            red_boxes[y_i] = True
        
        else:
            n_ball[x_i] -= 1
            n_ball[y_i] += 1
    
    
    
print(red_boxes.count(True))

Solution (Python):

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

ans = 0


jud = [0] + [1] * (n - 1)
num = [1] * n

for i in xy:
    if num[i[0] - 1] >= 2 and jud[i[0] - 1] == 0:
        jud[i[1] - 1] = 0
        num[i[0] - 1] -= 1
        num[i[1] - 1] += 1
    elif num[i[0] - 1] < 2 and jud[i[0] - 1] == 0:
        jud[i[1] - 1] = 0
        jud[i[0] - 1] = 1
        num[i[0] - 1] -= 1
        num[i[1] - 1] += 1
    else:
        num[i[0] - 1] -= 1
        num[i[1] - 1] += 1

print(jud.count(0))

Solution (Python):
boxnum, sousanum = map(int, input().split(" "))
sousa = []
for i in range(sousanum):
  sousa.append(list(map(int, input().split(" "))))


ball = [[1, 0] for i in range(boxnum)]
ball[0][1] = 1
for i in range(sousanum):
  if ball[sousa[i][0] - 1][1] == 1:
    ball[sousa[i][1] - 1][1] = 1
    
  ball[sousa[i][0] - 1][0] -= 1
  ball[sousa[i][1] - 1][0] += 1
  
  if ball[sousa[i][0] - 1][0] == 0:
    ball[sousa[i][0] - 1][1] = 0
total = 0
for i in range(boxnum):
    total += ball[i][1]
print(total)

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

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

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

ans = [1] * (n)
ans[0] = 1
ball = [0] * (n)
ball[0] = 1
for i in range(m):
    x, y = xy[i]
    ans[y-1] += 1
    ans[x-1] -= 1
    if ball[x-1]:
      ball[y-1] = 1
    if ans[x-1] == 0:
      ball[x-1] = 0
      
print(sum(ball))

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

ans = [1] * (n)
ans[0] = 1
ball = [False] * (n)
ball[0] = True
for i in range(m):
    x, y = xy[i]
    ans[y-1] += 1
    ans[x-1] -= 1
    if ball[x-1]:
      ball[y-1] = True
    if ans[x-1] == 0:
      ball[x-1] = False
      
cnt = 0
for i in ball:
  if i:
    cnt += 1

print(cnt)

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

print(c)

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

Solution (Python):

n, m = map(int, input().split())
L = [1]*n
R = [1] + [0]*~-n
for _ in range(m):
  x, y = map(int, input().split())
  x -= 1;y -= 1
  if R[x]:R[y] = 1
  L[x] -= 1;L[y] += 1
  R[x] *= (L[x] > 0)
print(sum(R))

Solution (Python):
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())

opes = []
for _ in range(M):
    x, y = map(int, sys.stdin.readline().rstrip().split())
    opes.append((x-1, y-1))

transported = set()
transported.add(0)
boxes = [1 for _ in range(N)]

for (x, y) in opes:
    boxes[x] -= 1
    boxes[y] += 1
    if x in transported:
        transported.add(y)
    if boxes[x] == 0 and x in transported:
        transported.remove(x)

print(len(transported))

Solution (Python):
N,M=map(int,input().split(' '))
B = [1]*N
R = [1]+[0]*(N-1)
for i in range(M):
    x,y=map(lambda x:int(x)-1,input().split(' '))
    B[x]-=1
    B[y]+=1
    if R[x] and B[x]:
        R[y]=1
    elif R[x] and not B[x]:
        R[x]=0
        R[y]=1
print(sum(R))

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

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

A = [1] * (n + 1)
red = [False] * (n + 1)
red[1] = True

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

print(len([red[i] for i in range(1, n + 1) if red[i]]))

Solution (Python):
def main():
    N, M = (int(_) for _ in input().split())
    haco = [1] * (N+1)
    
    cc = [1] * (N+1)
    haco[1] = 2
    for i in range(M):
        x, y = (int(_) for _ in input().split())
        cc[x] -= 1
        cc[y] += 1
        if haco[x] == 1:
            haco[y] = 3 if haco[y] in (2, 3) else 1
        elif haco[x] == 2:
            haco[y] = 2 if haco[y] == 0 else 3
        else:
            haco[y] = 3
        if cc[x] == 0: haco[x] = 0
    output = 0
    for i in range(1, N+1):
        if haco[i] in (2, 3):
            output += 1
    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
ball_count = [1 for _ in range(N)]
if_red_exists = [1] + [0 for _ in range(N-1)]
count = 1
for _ in range(M):
    x, y = map(int, input().split())
    if if_red_exists[x-1]:
        
        if_red_exists[y-1] = 1
        if ball_count[x-1] <= 1:
            if_red_exists[x-1] = 0
    ball_count[x-1] -= 1
    ball_count[y-1] += 1

count = 0
for e in if_red_exists:
    if e == 1:
        count += 1
print(count)

Solution (Python):

import sys


def main():
    N, M = map(int, input().split())
    red = [0] * N
    red[0] = 1
    num = [1] * N

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

if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())
l = [1] * n
d = set()
d.add(1)

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

s = 0
for i in d:
    if(l[i-1] != 0):s += 1
print(s)

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    possible = [0] * N
    possible[0] = 1
    ball_cnt = [1] * N
    for _ in range(M):
        x,y = map(int,input().split())
        x -= 1
        y -= 1
        if possible[x]:
            possible[y] = 1
            if ball_cnt[x] == 1:
                possible[x] = 0
        ball_cnt[x] -= 1
        ball_cnt[y] += 1
    ans = sum((b > 0)*p for b,p in zip(ball_cnt,possible))
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
l=[]
for _ in range(m):
    l.append(list(map(int,input().split())))
a=[0]*(n+1)
a[1]=1
c=[1]*(n+1)
for i in range(m):
    c[l[i][0]]-=1
    c[l[i][1]]+=1
    if a[l[i][0]]:
        a[l[i][1]]=1
    if c[l[i][0]]==0:
        a[l[i][0]]=0
print(a.count(1))

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

n, m = map(int, input().split())
x = [0]* n
y = [0]* n

box = [[1, 0] for _ in range(n)]
box[0] = [0,1]

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

    if box[x][1]>0:
        box[x][1] = box[x][1]-1
        box[y][1] = box[y][1] + box[y][0] + 1
        box[y][0] = 0
    else:
        box[x][0] = box[x][0]-1
        if box[y][1]>0:
            box[y][1] = box[y][1]+1
        else:
            box[y][0] = box[y][0]+1

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

print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,M=map(int,readline().split())
    x=[0]*M
    y=[0]*M
    for i in range(M):
        x[i],y[i]=map(int,readline().split())

    box=[1]*(N+1)
    flags=[False]*(N+1)
    flags[1]=True

    for i in range(M):
        out=x[i]
        inn=y[i]
        if flags[out]==True and box[out]==1:
            flags[out]=False
            flags[inn]=True
        elif flags[out]==True:
            flags[inn]=True
        box[out]-=1
        box[inn]+=1

    res=0
    for i in range(N+1):
        if flags[i]==True:
            res+=1
    print(res)
        
if __name__=="__main__":
    main()

Solution (Python):

n,m = list(map(int, input().split()))
manu = []

for i in range(m):
    manu.append(list(map(int, input().split())))

num = [1 for i in range(n+1)]
poss = [0 for i in range(n+1)]
poss[1] = 1

for i in range(m):
    a,b = manu[i][0],manu[i][1]
    if(poss[a]==1):
        poss[b]=1
    num[a]-=1
    num[b]+=1
    if(num[a]==0):
        poss[a]=0

print(sum(poss))

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


def main():
    N, M = map(int, input().split())
    x = [0] * M
    y = [0] * M
    for i in range(M):
        x[i], y[i] = map(int, input().split())

    ball = [1] * N
    exist = [0] * N
    exist[0] = 1
    for a, b in zip(x, y):
        ball[a-1] -= 1
        ball[b-1] += 1
        if exist[a-1] == 1:
            exist[a-1] = 1 if ball[a-1] > 0 else 0
            exist[b-1] = 1

    ans = sum(exist)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

def transfer(state, x, y):
    state[x][0] -= 1
    state[y][0] += 1
    if state[x][0] == 0:
        if state[x][1] == 1:
            state[x][1] = 0
            state[y][1] = 1
    else:
        if state[x][1] == 1:
            state[y][1] = 1
            
n, m = map(int, input().split())

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

print(np.sum(state, axis=0)[1])

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

balls = [1 for _ in range(n)]
red = [1] + [0 for _ in range(1,n)]

for _ in range(m):
  x, y = map(int,input().split())
  x,y = x-1, y-1
  
  if balls[x] ==0:
    continue
    
  balls[x] -= 1
  balls[y] += 1
  if red[x]:
    red[y] = 1
  if balls[x]==0:
    red[x] = 0
print(sum(red))

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

Ball = [1] * n
Done = [False] * n
Done[0] = True

for i in range(m):
	x, y = XY[i]
	x -= 1
	y -= 1
	if Done[x]:
		Done[y] = True
	
	Ball[x] -= 1
	Ball[y] += 1
	
	if Ball[x] == 0:
		Done[x] = False
				
res = 0
for i in range(n):
	if Done[i]:
		res += 1

print(res)

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

n, m = map(int, readline().split())
xy = [list(map(int, readline().split())) for _ in range(m)]
flag = [False] * n
flag[0] = True
cnt = [1] * n
for x, y in xy:
    if flag[x - 1]:
        flag[y - 1] = True
    cnt[x - 1] -= 1
    cnt[y - 1] += 1
    if cnt[x - 1] == 0:
        flag[x - 1] = False
print(flag.count(True))

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

possibility=[False]*n
possibility[0]=True
count=[1]*n

for x,y in a:
    if possibility[x-1]==True and count[x-1]>1:
        possibility[y-1]=True
    elif possibility[x-1]==True and count[x-1]==1:
        possibility[x-1]=False
        possibility[y-1]=True
    count[x-1]-=1
    count[y-1]+=1

print(possibility.count(True))

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

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

Solution (Python):
int1 = lambda x: int(x) - 1

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

red = [True] + [False] * (N-1)
n_ball = [1] * N

for _ in range(M):
    x,y = map(int1, input().split())
    if red[x]:
        red[y] = True
        n_ball[x] -= 1
        n_ball[y] += 1
        if n_ball[x] == 0:
            red[x] = False
    else:
        n_ball[x] -= 1
        n_ball[y] += 1

print(sum(red))

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

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

ans=0

for chk in check:
    if chk:
        ans+=1

print(ans)

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

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

print(check.count(True))

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    lis=[1]*n
    rlis=[False]*n
    rlis[0]=True
    for i in range(m):
        x,y=map(int,input().split())
        x-=1
        y-=1
        if lis[x]==1:
            lis[x]-=1
            lis[y]+=1
            if rlis[x]:
                rlis[x]=False
                rlis[y]=True
        else:
            lis[x]-=1
            lis[y]+=1
            if rlis[x]:
                rlis[y]=True
    print(rlis.count(True))


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    lis=[1]*n
    rlis=[False]*n
    rlis[0]=True
    for i in range(m):
        x,y=map(int,input().split())
        x-=1
        y-=1
        if lis[x]==1:
            lis[x]-=1
            lis[y]+=1
            if rlis[x]:
                rlis[x]=False
                rlis[y]=True
        else:
            lis[x]-=1
            lis[y]+=1
            if rlis[x]:
                rlis[y]=True
    print(rlis.count(True))


if __name__=='__main__':
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(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()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]

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

for a, b in L:
    if num[a-1] == 0:
        
        red[a-1] = False
        continue
    else:
        num[b-1] += 1
        num[a-1] -= 1
        red[b-1] = red[b-1] or red[a-1]
        if num[a-1] == 0:
            red[a-1] = False
    
print(sum(red))

Solution (Python):

















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

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    
    
    
    
    nums = [1] * n
    In = [False] * n
    In[0] = True
    for i in range(m):
        a,b = map(lambda x:int(x) - 1, input().split())
        nums[a] -=1
        nums[b] +=1
        if In[a]:
            In[b] = True
        if nums[a] == 0:
            In[a] = False
    cnt = 0
    
    for i in range(n):
        if In[i]:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
  main()

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

moves = [list(map(int,input().split())) for i in range(M)]
isRed = [False for i in range(N)]
isRed[0] = True
Ball = [1 for i in range(N)]

for i in range(M):
    p = moves[i][0] - 1
    q = moves[i][1] - 1

    if isRed[p] == True:
        isRed[q] = True
        Ball[p] -= 1
        Ball[q] += 1
        if Ball[p] < 1:
            isRed[p] = False
        
    else:
        Ball[p] -= 1
        Ball[q] += 1
    
ans = isRed.count(True)

print(ans)

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

flag_memo = [False]*n
flag_memo[0] = True

kazu_li = [1]*n


for a in all_li:
    kazu_li[a[0]-1] -= 1
    kazu_li[a[1]-1] += 1
    if flag_memo[a[0]-1]:
        flag_memo[a[1]-1] = True
    if kazu_li[a[0]-1] == 0:
        flag_memo[a[0]-1] = False
print(flag_memo.count(True))

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

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

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

cnt = 0
for el in red:
    if el:
        cnt += 1
print(cnt)

Solution (Python):
import copy
N, M = map(int, input().split())
XY = []
for _ in range(M):
    x, y = map(int, input().split())
    XY.append([x - 1, y - 1])

ball_num = [1] * N
is_red = [False] * N
is_red[0] = True

for i in range(M):
    s = XY[i][0]
    g = XY[i][1]
    if is_red[s]:
        if ball_num[s] == 1:
            ball_num[s] -= 1
            ball_num[g] += 1
            is_red[s] = False
            is_red[g] = True
        else:
            ball_num[s] -= 1
            ball_num[g] += 1
            is_red[g] = True
    else:
        ball_num[s] -= 1
        ball_num[g] += 1

print(sum(is_red))

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

num_l=[1 for i in range(n)]
bit_l=[1]+[0 for i in range(n-1)]

for x,y in l:
  x-=1
  y-=1

  if bit_l[x]==1:
    bit_l[y]=1
    if num_l[x]==1:
      bit_l[x]=0
  num_l[x]-=1
  num_l[y]+=1

print(bit_l.count(1))

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

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

box = [1]*n

red = [0]*n

red[0] = 1

for x,y in ab:
    if 0 < red[x]:
        red[y] = 1
    box[x] -= 1
    box[y] += 1

    if box[x] == 0:
        red[x] = 0
print(sum(red))

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

ans = set([0])
cnt = [1] * N
for _ in range(M):
    x,y = [int(i) - 1 for i in input().split()]
    cnt[x] -= 1; cnt[y] += 1
 
    if x in ans:
        ans.add(y)
        if cnt[x] == 0: 
            ans.remove(x)
 
print(len(ans))

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

prob=[0]*N
prob[0]=1
num=[1]*N
num[0]=1

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

Solution (Python):
from collections import defaultdict
n,m=map(int, input().split())
v = [0]*n
v[0]=1
ans = [1]*n
fi = 1
for i in range(m):
    a,b=map(int, input().split())
    ans[a-1]-=1
    ans[b-1]+=1
    if v[a-1]:
        v[b-1]=1
        fi+=1
    if ans[a-1]==0:
        v[a-1]=0
        fi-=1

print(sum(v))

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

Solution (Python):
N, M = map(int,input().split())
B = [list(map(int,input().split())) for k in range(M)]
H = [1]*N
E = [0]*N
E[0] = 1
for e in B:
    x, y = e[0]-1, e[1]-1
    if E[x] == 1:
        if H[x] == 1:
            E[x] = 0
            E[y] = 1
        else:
            E[y] = 1
    H[x] -= 1
    H[y] += 1
print(E.count(1))

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

Solution (Python):
n,m = map(int,input().split())
xy = [[int(i) for i in input().split()] for _ in range(m)]
num = [1]*n
red = [False]*n
red[0] = True
flag = True
for i in range(m):
    p = xy[i][0]
    q = xy[i][1]
    num[p-1] -= 1
    num[q-1] += 1
    if red[p-1]==True:
        red[q-1] = True
    
    if num[p-1]==0:
        red[p-1] = False
        

count = 0
for i in range(n):
    if num[i]>0 and red[i]:
        count += 1
print(count)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,M=map(int,input().split())
    X, Y = [0] * M, [0] * M
    for i in range(M):
        X[i], Y[i] = map(int, input().split())

    red=[True]+[False]*(N-1)
    cnt=[1]*N

    for i in range(M):
        cnt[X[i]-1]-=1
        cnt[Y[i]-1]+=1
        if red[X[i]-1]:
            red[Y[i]-1]=True
        if cnt[X[i]-1]==0:
            red[X[i] - 1]=False

    print(red.count(True))


resolve()

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

W = [1] * (N + 1)
W[1] = 0
R = [0] * (N + 1)
R[1] = 1
cnt = [1] * (N + 1)

for _ in range(M):
    fr, to = map(int, input().split())
    cnt[fr] -= 1
    cnt[to] += 1

    if R[fr] == 1 and W[fr] >= 1:
        R[to] = 1
        W[to] += 1

    if R[fr] == 1 and W[fr] == 0:
        R[fr] = 0
        R[to] = 1

    if R[fr] == 0 and W[fr] >= 1:
        W[fr] -= 1
        W[to] += 1

    if cnt[fr] == 0:
        W[fr] = 0
        R[fr] = 0

ans = len([0 for r in R if r >= 1])
print(ans)

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

num_l=[1 for i in range(n)]
bit_l=[1]+[0 for i in range(n-1)]

for x,y in l:
  x-=1
  y-=1
  if bit_l[x]==1 and num_l[x]==1:
    bit_l[x]=0
    bit_l[y]=1
    num_l[x]-=1
    num_l[y]+=1
  elif bit_l[x]==1 and num_l[x]>=2:
    bit_l[y]=1
    num_l[x]-=1
    num_l[y]+=1
  else:
    num_l[x]-=1
    num_l[y]+=1

print(bit_l.count(1))

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

Solution (Python):
def main():
    N, M = (int(i) for i in input().split())
    XY = [[int(i)-1 for i in input().split()] for j in range(M)]
    red = [False]*N
    red[0] = True
    cnt = [1]*N
    for x, y in XY:
        cnt[x] -= 1
        cnt[y] += 1
        if red[x]:
            red[y] = True
        if cnt[x] == 0:
            red[x] = False
    print(red.count(True))


if __name__ == '__main__':
    main()

Solution (Python):



N,M = map(int, input().split())
xy = [tuple(map(int, input().split())) for _ in range(M)]

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

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

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

print(ans)

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

exred = [i == 0 for i in range(N)]
n_ball = [1] * N

for i, (xi, yi) in enumerate(xy):
    exred[yi - 1] = exred[xi - 1] | exred[yi - 1]
    n_ball[xi - 1] -= 1
    n_ball[yi - 1] += 1
    if n_ball[xi - 1] == 0: exred[xi - 1] = False

ans = sum([int(item == True) for item in exred])
print(ans)

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

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

Solution (Python):
def main():
    n, m = map(int, input().split())
    x = [None] * m
    y = [None] * m
    for i in range(m):
        x[i], y[i] = map(int, input().split())

    ball = [1] * n
    red = [False] * n
    red[0] = True
    for i in range(m):
        if red[x[i]-1]:
            red[y[i]-1] = True
        ball[x[i]-1] -= 1
        ball[y[i]-1] += 1
        if ball[x[i]-1] == 0:
            red[x[i]-1] = False

    print(sum(red))

if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = [1]*n
    f = [0]*n
    f[0] = 1
    for _ in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        s[a] -= 1
        s[b] += 1
        if f[a]:
            f[b] = 1
            if s[a] == 0:
                f[a] = 0
    print(sum(f))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
"""
@author:  wangquaxiu
@time:  2020/4/20 22:04
"""


n,m = map(int,input().split())
box = [[1,0] for _ in range(n+1)]
box[1][1] = 1

count = 0
for i in range(m):
    x,y = map(int,input().split())
    if(box[x][0] == 1 and box[x][1] == 1):
        box[x][1] = 0
        box[y][1] = 1
    elif(box[x][1] == 1):
        box[y][1] = 1

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

for b in box:
    if(b[1] == 1):
        count+=1

print(count)

Solution (Python):
def main():
    n,m=map(int,input().split())
    cnt=[1]*n
    res=[0]*n
    res[0]=1
    for i in range(m):
        x,y=map(int,input().split())
        if res[x-1]==1:
            res[y-1]=1
            if cnt[x-1]==1:
                res[x-1]=0
        cnt[x-1]-=1
        cnt[y-1]+=1
    print(sum(res))
if __name__=="__main__":
    main()

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

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