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())
xy = [list(map(int, input().split())) for _ in range(m)]
red = [0] * (n+1)
red[1] = 1
ball = [1] * (n+1)
for x,y in xy:
    ball[x] -= 1
    ball[y] += 1
    if red[x] == 1:
        red[y] = 1
        if ball[x] == 0: red[x] = 0
print(sum(red))

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

print(sum(aka))

Solution (Python):
N, M, *xy = map(int, open(0).read().split())
boxes = [{"count": 1, "red": False} for _ in range(N)]
boxes[0]["red"] = True

for x, y in zip(*[iter(xy)] * 2):
    x -= 1
    y -= 1
    if boxes[x]["red"]:
        boxes[y]["red"] = True
        if boxes[x]["count"] == 1:
            boxes[x]["red"] = False
    boxes[x]["count"] -= 1
    boxes[y]["count"] += 1
print(sum(b["red"] for b in boxes))

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

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

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

ans = 0
for v in red_flag:
    if v: ans += 1

print(ans)

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

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

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

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

in_group = set()
in_group.add(1)

boll_num = {}
for i in range(n):
    boll_num[i+1] = 1


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

print(len(in_group))

Solution (Python):
def solve():
    N, M = map(int, input().split())
    contains_redball = [False] * N
    contains_redball[0] = True
    balls_cnt = [1] * N
    for _ in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        balls_cnt[x] -= 1
        balls_cnt[y] += 1
        if contains_redball[x]:
            contains_redball[y] = True
        if balls_cnt[x] == 0:
            contains_redball[x] = False
    print(sum(contains_redball))

if __name__ == '__main__':
    solve()

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

red = [0]*N
red[0] = 1

q = [1]*N

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

print(sum([1 for i in range(N) if q[i]>0 and red[i]]))

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

H=[False]*(N+1)
H[1]=True

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

    H[Y]|=H[X]

    Z[X]-=1
    Z[Y]+=1

    H[X]&=(Z[X]!=0)
print(sum(H))

Solution (Python):
import sys












stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    
    n,m = map(int, stdin.readline().rstrip().split())
    
    
    
    
    
    red = [0] * n
    red[0] = 1
    ball = [1] * n
    for i in range(m):
        x,y = map(int, stdin.readline().rstrip().split())
        if red[x-1] != 0 and ball[x-1] != 1:
            red[y-1] = 1
            ball[x-1] -= 1
            ball[y-1] += 1
        elif red[x-1] != 0 and ball[x-1] == 1:
            red[x-1] = 0
            red[y-1] = 1
            ball[x-1] -= 1
            ball[y-1] += 1
        else:
            ball[x-1] -= 1
            ball[y-1] += 1
    print(sum(red))


if __name__ == '__main__':
    solve()

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

aka_list = [True]
for i in range(1, n):
    aka_list.append(False)
balls = [1] * n

for i in range(m):
    if aka_list[x_y[i][0] - 1]:
        aka_list[x_y[i][1]-1] = True
    balls[x_y[i][0] - 1] -= 1
    balls[x_y[i][1] - 1] += 1
    if balls[x_y[i][0] - 1] == 0:
        aka_list[x_y[i][0] - 1] = False

print(sum([1 for i in range(len(aka_list)) if aka_list[i]]))

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

Solution (Python):

def solve():
    N, M = map(int, input().split())
    exist = [1] * N
    red = [False] * N
    red[0] = True
    for i in range(M):
        x, y = map(int, input().split())
        x -= 1; y -= 1
        exist[x] -= 1; exist[y] += 1
        if red[x]:
            red[y] = True
        if exist[x] == 0:
            red[x] = False
    ans = 0
    for i in range(N):
        if red[i] and exist[i] > 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

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

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

N,M=list(map(int,input().split()))
ball = [0]*(N+1)
ball[1]=1
ball_num = [1]*(N+1)
for i in range(M):
    x,y=map(int,input().split())
    if ball[x]==1:
        ball[y]=1
    ball_num[x]-=1
    ball_num[y]+=1
    if ball_num[x]==0:
        ball[x]=0
    
cnt = 0
for a,b in zip(ball_num,ball):
    cnt += (a!=0 and b != 0)
print(cnt)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
x = []
for i in range(m):
    x0, x1 = MAP()
    x.append([x0-1, x1-1])

r = [0]*n
w = [1]*n
t = [1]*n
r[0] = 1
w[0] = 0

for y in x:
    t[y[0]] -= 1
    t[y[1]] += 1

    if r[y[0]] > 0 and w[y[0]] == 0:
        r[y[0]] = 0
        r[y[1]] = 1
    elif r[y[0]] == 0 and w[y[0]] > 0:
        w[y[0]] -= 1
        w[y[1]] += 1
    elif r[y[0]] > 0 and w[y[0]] > 0:
        r[y[1]] = 1
        w[y[1]] += 1
    if t[y[0]] == 0:
        r[y[0]] = w[y[0]] = 0

ans = sum(r)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
boxes = [0]*N
balls = [1]*N
boxes[0] = 1
for _ in range(M):
    x, y = mapint()
    boxes[y-1] = 1 if boxes[x-1]==1 else boxes[y-1]
    balls[x-1] -= 1
    balls[y-1] += 1
    if balls[x-1]==0:
        boxes[x-1] = 0

print(sum(boxes))

Solution (Python):


def main():
    N, M = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(M)]
    box = [1] * N
    red_flag = [0] * N
    red_flag[0] = 1
    ans = 0
    for i in range(M):
        if red_flag[xy[i][0] - 1] == 1:
            red_flag[xy[i][1] - 1] = 1
        box[xy[i][0] - 1] -= 1
        if box[xy[i][0] - 1] == 0:
            red_flag[xy[i][0] - 1] = 0
        box[xy[i][1] - 1] += 1
    print(sum(red_flag))


if __name__ == "__main__":
    main()

Solution (Python):


def main():
    N, M = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(M)]
    box = [1] * N
    red_flag = [0] * N
    red_flag[0] = 1
    ans = 0
    for i in range(M):
        if red_flag[xy[i][0] - 1] == 1:
            red_flag[xy[i][1] - 1] = 1
        box[xy[i][0] - 1] -= 1
        if box[xy[i][0] - 1] == 0:
            red_flag[xy[i][0] - 1] = 0
        box[xy[i][1] - 1] += 1
    for i in range(N):
        if box[i] != 0 and red_flag[i] == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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


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

boxes = [1] * (N + 1)
boxes[0] = 0

ball_exists = set()
ball_exists.add(1)

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

  boxes[x] -= 1
  boxes[y] += 1
  
  if x in ball_exists:
    if boxes[x] == 0:
      ball_exists.remove(x)

      if len(ball_exists) == 1 and y in ball_exists:
        ball_exists.clear()

    ball_exists.add(y)

  
  

print(len(ball_exists))

Solution (Python):
import collections
n,m = map(int,input().split())
box = [[1,"white"] for i in range(n)]
box[0][1] = "red"
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    if box[x][1] == "red":
        box[y][1] = "red"
    box[y][0] += 1
    box[x][0] -= 1
    if box[x][0] == 0:
        box[x][1] = "white"
ans = 0
for i in range(n):
    if box[i][1] == "red":
        ans += 1
print(ans)

Solution (Python):
(n, m), *q = [[*map(int, i.split())] for i in open(0)]
b = [0] * (n + 1)
b[1] = 1
c = [1] * (n + 1)
for x, y in q:
    c[x] -= 1
    c[y] += 1
    b[y] |= b[x]
    b[x] *= c[x] > 0
print(sum(b))

Solution (Python):

(n, m), *q = [[*map(int, i.split())] for i in open(0)]
b = [1] + [0] * (n - 1)
c = [1] * n
for x, y in q:
    c[x - 1] -= 1
    c[y - 1] += 1
    b[y - 1] |= b[x - 1]
    b[x - 1] *= c[x - 1] > 0
print(sum(b))

Solution (Python):

(n, m), *q = [[*map(int, i.split())] for i in open(0)]
b = [1] + [0] * (n - 1)
c = [1] * n
for x, y in q:
    c[x - 1] -= 1
    c[y - 1] += 1
    b[y - 1] |= b[x - 1]
    if c[x - 1] == 0:
        b[x - 1] = 0
print(sum(b))

Solution (Python):






N,M = map(int, input().split())
xy = []
b = [1]*N
p = [False]*N
p[0] = True
for _ in range(M):
    x,y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1
    if p[x-1]:
        p[y-1] = True
    if b[x-1] == 0:
        p[x-1] = False





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

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

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

Solution (Python):

N, M = map(int,input().split())
flg = [False]*N
flg[0] = True
cnt = [1]*N
for i in range(M):
    x, y = map(int,input().split())
    if flg[x-1]:
        if cnt[x-1]>1:
            flg[y-1] = True
        elif cnt[x-1]==1:
            flg[y-1] = True
            flg[x-1] = False
        else:
            continue
        cnt[x-1]-=1
        cnt[y-1]+=1
    else:
        if cnt[x-1]>0:
            cnt[x-1]-=1
            cnt[y-1]+=1


print(flg.count(True))

Solution (Python):
N, M = list(map(int, input().split()))
C = [1] * (N + 1)
B = [True, True] + [False] * (N - 1)
flg = False
for _ in range(M):
    x, y = list(map(int, input().split()))
    if B[x]:
        B[y] = True
    if x == 1 and not flg and C[1] == 1:
        B[1] = False
        flg = True
    if y == 1 and not flg:
        flg = True
    C[x] -= 1
    C[y] += 1
    if C[x] == 0:
        B[x] = False
res = 0
for i in range(1, N + 1):
    if B[i] and C[i] > 0:
        res += 1
print(res)

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

Solution (Python):
N, M = map(int,input().split())
z = [list(map(int,input().split())) for i in range(M)]
box = [[1,1]]
for i in range(N-1):
  box.append([0,1])
for i in range(M):
  box[z[i][0]-1][1] -= 1
  box[z[i][1]-1][1] += 1
  if (box[z[i][0]-1][0] == 1):
    box[z[i][1]-1][0] = 1
  if (box[z[i][0]-1][1] == 0):
    box[z[i][0]-1][0] = 0
ans = 0
for i in range(N):
  if (box[i][0] != 0):
    ans += 1
print(ans)

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

may_red = [0] * N
may_red[0] = 1
balls = [1] * N

for x,y in XY:
    x,y = x-1,y-1
    if may_red[x]:
        may_red[y] = 1
        if balls[x] == 1:
            may_red[x] = 0
    balls[x] -= 1
    balls[y] += 1
print(sum(may_red))

Solution (Python):



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

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












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

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

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

boxl = [1]*(n+1)
redl = [False]*(n+1)
redl[1] = True

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

ans = 0
for r in redl:
    if r: ans += 1

print(ans)

Solution (Python):
import sys

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

N, M = inm()


def solve():
    r = [False] * N
    r[0] = True
    cnt = [1] * N
    for i in range(M):
        x, y = inm()
        x -= 1
        y -= 1
        if r[x]:
            r[y] = True
        cnt[x] -= 1
        cnt[y] += 1
        if cnt[x] == 0:
            r[x] = False

    return sum(r)


print(solve())

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

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

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

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

print(sum(X))

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

countR=[0]+[1]+[0]*(N-1)
countBall=[0]+[1]*N

for x,y in xy:
    countBall[x]-=1
    countBall[y]+=1
    if countR[x]>0:
        countR[y]+=1
    if countBall[x]<1:
        countR[x]=0

print(sum(r*b>0 for r,b in zip(countR,countBall)))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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





N, M = getNM()
que = []
for i in range(M):
    a, b = getNM()
    que.append([a - 1, b - 1])
ball = [1] * N
red = [0] * N
red[0] = 1

for a, b in que:
    ball[b] += 1
    if red[a] == 1:
        red[b] = 1
    ball[a] -= 1
    if ball[a] == 0:
        red[a] = 0
print(sum(red))

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter

from fractions  import gcd

import bisect
n,m=map(int,input().split())
num=[1]*n
s=set()
s.add(1)
ans=1
for i in range(m):
    x,y=map(int,input().split())
    num[x-1]-=1
    num[y-1]+=1
    if x in s:
        if num[x-1]!=0 and y not in s:
          ans+=1
        elif num[x-1]==0:
          s.discard(x)
          if y in s:
            ans-=1
        s.add(y)
print(ans)

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

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

num = [1 for i in range(N)]
red = [False for i in range(N)]
red[0] = True

for i in range(M):
    x, y = map(int, input().split())    
    x -= 1
    y -= 1
    
    if(red[x] and num[x] >= 1):
        red[y] = True
        num[x] -= 1
        num[y] += 1
        if(num[x] <= 0):
            red[x] = False
    else:
        if(num[x]):
            num[x] -= 1
            num[y] += 1

print(red.count(True))

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



def linput(ty=int, cnv=list):
    return cnv(map(ty, input().split()))

def vinput(rep=1, ty=int, cnv=list):
    return cnv(ty(input().rstrip()) for _ in "*"*rep)

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    N,M = linput()

    vR = [0, 1,] + [0,]*(N-1)
    vN = [0, 1,] + [1,]*(N-1)

    res = 0

    for _ in range(M):
        a,b = linput()
        if vR[a]:
            vR[b] = 1
        if vN[a]==1:
            vR[a] = 0

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

    res = sum(vR)
    print(res)
    
    
    
    

main()

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

lb = [False] * n
lb[0] = True
lbn = [1] * n

for i in range(m):
    x, y = [int(w)-1 for w in input().split()]
    if lb[x] and lbn[x] > 0:
        lb[y] = True
    lbn[x] -= 1
    lbn[y] += 1

    if lb[x] and lbn[x] == 0:
        lb[x] = False

print(len([_ for _ in lb if _]))

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    queries = [[int(item)-1 for item in input().split()] for _ in range(M)]

    memo = [['w'] for _ in range(N)]
    memo[0] = ['r']
    is_first_0 = True
    for x, y in queries:
        if 'r' in memo[x]:
            memo[y] += ['r']
            if 'w' in memo[x]:
                memo[x].remove('w')
            else:
                memo[x].remove('r')
        else:
            memo[y] += ['w']
            memo[x].remove('w')
    res = 0
    for line in memo:
        for item in set(line):
            if item == 'r':
                res += 1
    print(res)



if __name__ == "__main__":
    resolve()

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

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

ans = {1}
l = [1] * n

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

    if x in ans:
        if l[x - 1] == 0: ans.remove(x); ans.add(y)
        else: ans.add(y)
print(len(ans))

Solution (Python):


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

xy = []
for _ in range(m):
    x, y = map(int, input().split())
    xy.append((x - 1, y - 1))

box = [0] * n
box[0] = 1
num = [1] * n
for x, y in xy:
    if box[x]:
        box[y] |= 1
    num[x] -= 1
    num[y] += 1
    if not num[x]:
        box[x] = 0
ans = 0
for i in range(n):
    if box[i] and num[i]:
        ans += 1
print(ans)

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

red, cnt = set([1]), {i: 1 for i in range(1, n + 1)}
for xi, yi in xy:
    if xi in red:
        red.add(yi)
        if cnt[xi] == 1:
            red.remove(xi)
    cnt[xi] -= 1
    cnt[yi] += 1
print(len(red))

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=[1]*n
anslst=[0]*n
anslst[0]=1

for x,y in xy:
    x,y=x-1,y-1
    if anslst[x]==1:
        anslst[y]=1
    lst[x]-=1
    lst[y]+=1
    if lst[x]==0:
        anslst[x]=0

print(sum(anslst))

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n, m = [int(x) for x in input().split()]
    g = defaultdict(list)
    cnt = [1] * (n + 1)
    w = [0] * (n + 1)
    w[1] = 1
    for _ in range(m):
        a, b = [int(x) for x in input().split()]
        g[a].append(b)
        cnt[a] -= 1
        cnt[b] += 1
        if w[a]:
            if cnt[a] == 0:
                w[a] = 0
            w[b] = 1
    
    ans = 0
    for i in range(1, n+1):
        if cnt[i] and w[i]:
            ans += 1
    print(ans)
    

        
    
t = 1

for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

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

    if ball_in_boxes[x-1] == 0: 
        redball_flag[x-1] = False
print(redball_flag.count(True))

Solution (Python):


import itertools





def main():
    n, m = input_list()
    balls = [1] * n
    reds = [False] * n
    reds[0] = True
    for _ in range(m):
        x, y = input_list()
        if reds[x-1]:
            reds[y-1] = True
        balls[x-1] -= 1
        balls[y-1] += 1
        if balls[x-1] == 0:
            reds[x-1] = False
    c = 0
    for v in reds:
        if v:
            c += 1
    print(c)


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

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

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

Solution (Python):
n, m, *XY = map(int, open(0).read().split())
A = [1] * n
B = [0] * n
B[0] = 1
for x, y in zip(XY[::2], XY[1::2]):
  x, y = x-1, y-1
  A[x] -= 1
  A[y] += 1
  if B[x]:
    B[y] = 1
  if A[x] == 0:
    B[x] = 0
print(sum(B))

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

red=[0]*n
red[0]=1
cnt=[1]*n

for i in range(m):
    cnt[x[i]]-=1
    cnt[y[i]]+=1

    if red[x[i]]==1:
        red[y[i]]=1
    
    if cnt[x[i]]==0:
        red[x[i]]=0

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

print(ans)

Solution (Python):
def operate(x, y):
    if is_red[x]:
        is_red[y] = True
        if num_ball[x] == 1:
            is_red[x] = False
    num_ball[x] -= 1
    num_ball[y] += 1


if __name__ == "__main__":

    N, M = [int(x) for x in input().split(" ")]
    num_ball = [1 for _ in range(N)]
    is_red = [True] + [False for _ in range(N - 1)]

    for _ in range(M):
        x, y = [int(x) for x in input().split(" ")]
        x, y = x - 1, y - 1
        operate(x, y)
    print(sum(is_red))

Solution (Python):
def solve(n, m, x, y):
    x = list(map(lambda _:_-1, x))
    y = list(map(lambda _:_-1, y))
    p = [0] * n
    p[0] = 1
    c = [1] * n
    for i in range(m):
        if c[x[i]] > 1:
            if p[x[i]] == 1:
                p[y[i]] = 1
        else:
            if p[x[i]] == 1:
                p[y[i]] = 1
            p[x[i]] = 0
        c[x[i]] -= 1
        c[y[i]] += 1
    return sum(p)

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())
print(solve(n, m, x, y))

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n, m = map(int, input().split())
may_contain_red = [0 for _ in range(n + 1)]
num_of_ball = [1 for _ in range(n + 1)]
may_contain_red[1] = 1
for i in range(m):
    x, y = map(int, input().split())
    num_of_ball[x] -= 1
    num_of_ball[y] += 1
    if may_contain_red[x] != 0:
        may_contain_red[y] = 1
    if num_of_ball[x] == 0:
        may_contain_red[x] = 0

print(sum(may_contain_red))

Solution (Python):
N,M=map(int,input().split())
arr=[[0,1,0] for _ in range(N)]
arr[0]=[1,1,1]
for i in range(M):
  a,b=map(int,input().split())
  arr[a-1][1]-=1
  arr[b-1][1]+=1
  if arr[a-1][0]==1:
    arr[b-1][0]=1
  if arr[a-1][2]==1:
    arr[a-1][2],arr[b-1][2]=0,1
  if arr[a-1][1]==0:
    arr[a-1][0]=0
ans=0
for i in range(N):
  if arr[i][0]==1 and arr[i][1]!=0:
    ans+=1
print(ans)

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

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

ball=[1]*n
red=[0]*n
red[0]+=1

for i in range(m):
    if red[xy[i][0]-1]>=1:
        if ball[xy[i][0]-1]==1:
            red[xy[i][0]-1]=0
        red[xy[i][1]-1]+=1
    ball[xy[i][0]-1]-=1
    ball[xy[i][1]-1]+=1

ans=len(red)-red.count(0) 
print(ans)

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

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

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

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

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

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

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

for i in range(M):
  x,y = map(int,input().split())
  if A[0][x-1] > 0:
    A[0][y-1] += 1
  else:
    A[1][y-1] += 1
  if A[1][x-1] > 0:
    A[1][x-1] -= 1
  else:
    A[0][x-1] -= 1
print(len([i for i in A[0] if i > 0]))