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 = [int(x) for x in input().split()]
x = []
for i in range(m):
  x.append([int(x) for x in input().split()])
count = [1] * (n+1)
flag = [0] * (n+1)
flag[1] = 1
for i in range(m):
  if flag[x[i][0]] == 1:
    flag[x[i][1]] = 1
  if count[x[i][0]] == 1:
    flag[x[i][0]] = 0
  count[x[i][0]] -= 1
  count[x[i][1]] += 1

res = 0
for i in range(n+1):
  if flag[i] == 1:
    res += 1
    
print(res)

Solution (Python):
import numpy as np

N,M=map(int,input().split())
length=np.ones(N+1)
aka=np.ones(N+1)
aka[1]=-1

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

print(len(aka[aka<0]))

Solution (Python):
from collections import defaultdict
n, m = map(int, input().split())
r = set()
r.add(1)
d = defaultdict(int)
for i in range(m):
  x, y = map(int, input().split())
  d[x] -= 1
  d[y] += 1
  if x in r:
    r.add(y)
  if d[x] == -1 and x in r:
    r.remove(x)
ans = len(list(r))
for e in d:
  if d[e] == -1 and e in r:
    ans -= 1
print(ans)

Solution (Python):





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

R = [False] * (N + 1)
num = [1] * (N + 1)

R[1] = True

for x, y in Q:
    R[y] = R[x] or R[y]
    num[x] -= 1
    num[y] += 1

    if num[x] <= 0:
        R[x] = False

print(R.count(True))

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

ball = [1] * n
flag = [1] + [0] * (n-1)

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

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

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

    if ball[x] == 0:
        flag[x] = 0

print(sum(flag))

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

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

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

        else:
            r[y] = 1
            b[x] -= 1
            b[y] += 1

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

print(sum(r))

Solution (Python):
n,m = map(int,input().split())
dic = {}
ls = [1]*(n+1)
ls[0] = 0
ans = 0
dic[1] = 1
for i in range(m):
    a,b = map(int,input().split())
    ls[a] -= 1
    ls[b] += 1
    if dic.get(a,0) != 0:
        if dic.get(b,0) == 0:
            dic[b] = 1
    else:
        if ls[b] == 1:
            dic[b] = 0
for j in range(n+1):
    if ls[j] > 0 and dic.get(j,0) != 0:
        ans += 1
print(ans)

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

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

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

Solution (Python):
N, K = map(int, input().split())
r = [False for _ in range(N+1)]
b = [1 for _ in range(N+1)]
r[1] = True
r_cnt = 1
for _ in range(K):
  x, y = map(int, input().split())
  b[x] -= 1
  b[y] += 1
  if r[x]:
    if b[x] == 0:
      r[x] = False
      r_cnt -= 1
    if not r[y]:
      r[y] = True
      r_cnt += 1
print(r_cnt)

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

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

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

box = [1 for i in range(n)]

chk = [False for i in range(n)]
chk[0] = True
for i in range(m):
  x, y = xy[i][0],xy[i][1]
  if chk[x]:
    if box[x] >= 2:
      chk[y] = True 
    else:
      chk[y] = True
      chk[x] = False
  box[y] += 1
  box[x] -= 1
cnt = 0
for i in range(n):
  cnt += chk[i]
print (cnt)

Solution (Python):
n, m = list(map(int, input().split()))
cnt = [1] * n
has_red = [False] * n
has_red[0] = True
for i in range(m):
    a, b = list(map(int, input().split()))
    has_red[b - 1] = has_red[b - 1] or has_red[a - 1]
    if cnt[a - 1] == 1:
        has_red[a - 1] = False
    cnt[a - 1] -= 1
    cnt[b - 1] += 1
print(has_red.count(True))

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

box = []
box.append([1, True])
for _ in range(N - 1):
    box.append([1, False])

for _ in range(M):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1

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

    if box[x][1]:
        box[y][1] = True

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

Solution (Python):
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

N, M = mi()
x, y = i2(M)

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

for i in range(M):
    boxes[x[i]-1] -= 1
    boxes[y[i]-1] += 1

    if red[x[i]-1]:
        red[y[i]-1] = True
    if boxes[x[i]-1] == 0:
        red[x[i]-1] = False

print(red.count(True))

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

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    cnt = [None] + [1 for _ in range(n)]
    exist = [False] + [False for _ in range(n)]
    exist[1] = True

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

        cnt[y] += 1
        exist[y] |= exist[x]

        cnt[x] -= 1
        exist[x] &= cnt[x] != 0
    
    ans = sum(exist)
    print(ans)
main()

Solution (Python):
n, m = map(int, input().split())
l = [True if i == 0 else False for i in range(n)]
k = [1 for i in range(n)]
for i in range(m):
    xy = list(map(int, input().split()))
    if l[xy[0]-1]:
        if k[xy[0]-1] > 1:
            l[xy[1]-1] = True
        else:
            l[xy[1]-1] = True
            l[xy[0]-1] = False
    k[xy[0]-1] -= 1
    k[xy[1]-1] += 1
print(l.count(True))

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

redball = [0]*n
redball[0] = 1
ball_cnt = [1]*n

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

    if ball_cnt[x] == 1 and redball[x]:
        redball[x] = 0
        redball[y] = 1

    if ball_cnt[x] > 1 and redball[x]:
        redball[y] = 1

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

print(redball.count(1))

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

redball = [0]*n
redball[0] = 1
ball_cnt = [1]*n

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

    if ball_cnt[x] == 1 and redball[x] == 1:
        redball[x] = 0
        redball[y] = 1

    if ball_cnt[x] > 1 and redball[x] == 1:
        redball[y] = 1

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

print(redball.count(1))

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

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

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

dp = [False]*N
dp[0] = True
cnt = [1]*N

for _ in range(M):
    x,y = map(lambda x:int(x)-1,input().split())
    dp[y] = dp[y] or dp[x]
    cnt[y] += 1
    cnt[x] -= 1
    if cnt[x] == 0:
        dp[x] = False

print(sum(dp))

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

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

D = [0] * N
C = [1] * N
D[0] = 1

for x, y in xy:
  x -= 1
  y -= 1
  if D[x] == 1:
    D[y] = 1
  C[x] -= 1
  C[y] += 1
  if C[x] == 0:
    D[x] = 0

print(sum(D))

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*N
    L[0]=1
    cnt=[1]*N
    for i in range(M):
        x,y=MI()
        x-=1
        y-=1
        if L[x]==1:
            L[y]=1
            if cnt[x]==1:
                L[x]=0
                flag=0
        cnt[x]-=1
        cnt[y]+=1
                
    print(sum(L))
        

main()

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

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

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

Solution (Python):
n,m=map(int,input().split())
dp=[False]*n
dp2=[1]*n

dp[0]=True

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

for i in range(n):
  if dp[i]==True:
    ans+=1
    
    
print(ans)

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

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

Solution (Python):
import math
from math import gcd,pi
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,m = i_map()
    box = [1 for _ in range(n+1)]
    red = [0 for _ in range(n+1)]
    red[1] = 1

    for i in range(m):
        x,y = i_map()
        box[x] -= 1
        box[y] += 1
        if red[x] == 1:
            red[y] = 1
        if box[x] == 0:
            red[x] = 0

    print(sum(red))

if __name__=="__main__":
    main()

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

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

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

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

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

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

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

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

for i in range(m):
    x,y = L[i][0],L[i][1]
    x,y = x-1,y-1
    if kosuu[x] >=2 and possible[x] == 1:
        possible[y] = 1
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 1:
        possible[x] = 0
        possible[y] = 1
        kosuu[x] = 0
        kosuu[y] +=1
    elif kosuu[x] >=2 and possible[x] == 0:
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 0:
        kosuu[x] = 0
        kosuu[y] +=1
print(sum(possible))

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))




def main():
	n,m=MI()
	A=[1]*(n+1)
	ans=[0]*(n+1)
	ans[1]=1

	for _ in range(m):
		x,y=MI()
		if ans[x]==1:
			ans[y]=1
		if A[x]==1 and ans[x]==1:
			ans[x]=0
		A[x]-=1
		A[y]+=1
		

	print(sum(ans))









if __name__ == "__main__":
	main()

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

Solution (Python):
N, M = map(int, input().split())
kouho = {}
kouho[1]=True
Nlist = [1]*(N+1)
ans = 0
for i in range(M):
    x, y = map(int, input().split())
    if x in kouho:
        kouho[y] = True
        Nlist[x] -= 1
        Nlist[y] += 1
    else:
        Nlist[x] -= 1
        Nlist[y] += 1
    if Nlist[x]==0:
        if x in kouho:
            del kouho[x]

for i in range(1, N+1):
    if Nlist[i] == 0:
        continue
    if i in kouho:
        ans += 1

print(ans)

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

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

ball_count = [1]*N

red_ball_cand = [0]*N
red_ball_cand[0] = 1

for i in range(M):
    x,y = XY[i]
    x,y = x-1,y-1
    if 0 < red_ball_cand[x]:
        red_ball_cand[y] = 1
        
    ball_count[x] -= 1
    ball_count[y] += 1
    
    if ball_count[x] == 0:
        red_ball_cand[x] = 0
print(sum(red_ball_cand))

Solution (Python):
N, M, *xy = map(int, open(0).read().split())
boxes = [1] * N
is_red = [0] * N
is_red[0] = 1

for x, y in zip(*[iter(xy)] * 2):
    x -= 1
    y -= 1
    boxes[x] -= 1
    boxes[y] += 1
    if is_red[x]:
        if boxes[x] == 0:
            is_red[x] = 0
        is_red[y] = 1
print(sum(is_red))

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

red = [False] * n
ball = [1] * n

red[0] = True
for _ in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    if red[x]:
        red[y] = True
        if ball[x] == 1:
            red[x] = False
    ball[y] += 1
    ball[x] -= 1
print(len(list(filter(lambda x: x, red))))

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

B = [1 for i in range(N)]
R = [0 for i in range(N)]
R[0] = 1 
for i in range(M):
  src = Z[i][0]-1
  dst = Z[i][1]-1
  if B[src] > 1 and R[src] == 1:
    R[dst] = 1
  if B[src] == 1 and R[src] == 1:
    R[src] = 0 
    R[dst] = 1
  B[src] -= 1
  B[dst] += 1
print(sum(R))

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

Solution (Python):
n,m=map(int,input().split())
red=[0]*(n+1)
red[1]=1
balls=[1]*(n+1)
for i in range(m):
  x,y=map(int,input().split())
  if red[x]==1:
    red[y]=1
  balls[x]-=1
  balls[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+1)
red = [0] * (n+1)
red[1] = 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())
redl = [False]*(n+1)
redl[1] = True
cnts = [1]*(n+1)
cnts[0] = 1

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

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

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

check = [1]+[0]*n
numlis = [1]*(n+1)

for i in range(m):
    x, y = map(int, input().split())
    if numlis[x-1] > 1 and check[x-1] == 1:
        check[y-1] = 1
        numlis[x-1] -= 1
        numlis[y-1] += 1
    elif numlis[x-1] == 1 and check[x-1] == 1:
        check[y-1] = 1
        check[x-1] = 0
        numlis[x-1] -= 1
        numlis[y-1] += 1
    else:
        numlis[x-1] -= 1
        numlis[y-1] += 1
    

print(sum(check))

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, m = map(int, input().split())
    balls = [1] * (n + 1)
    posib = [0] * (n + 1)
    posib[1] = 1
    m = map(int, read().split())
    ab = zip(m, m)
    for x, y in ab:
        if posib[x]:
            posib[y] = 1
        balls[y] += 1
        balls[x] -= 1
        if not balls[x]:
            posib[x] = 0
    r = sum(posib)
    print(r)

if __name__ == '__main__':
    main()

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

    ball  = [0, 1] + [1 for i in range(N - 1)]
    rflag = [0, 1] + [0 for i in range(N - 1)] 

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

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

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

        if ball[x] == 0:
            rflag[x] = 0

    ans = sum(rflag[1:])
    print(ans)
    
if __name__ == "__main__":
    main3()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    XY = [[int(x) for x in input().split()] for _ in range(M)]
    ans = [0] * (N + 1)
    ans[1] = 1
    cnt = [1] * (N + 1)
    for x, y in XY:
        if ans[x] == 1:
            ans[y] = 1
        if cnt[x] == 1:
            ans[x] = 0
        cnt[x] -= 1
        cnt[y] += 1

    print(sum(ans))


if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np

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

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

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

tmp1 = 0
tmp2 = 0

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

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

print(int(ans))

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

    num_balls = [1] * n
    red_prov = [False] * n
    red_prov[0] = True

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

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

        
        if red_prov[x]:
            red_prov[y] = True

        if num_balls[x] == 0:
            red_prov[x] = False

    print(sum(red_prov))
    
resolve()

Solution (Python):
def main():
    N, M = list(map(int, input().split()))
    proc_list = [list(map(lambda z: int(z) - 1, input().split())) for _ in range(M)]
    counter = [1] * N
    red_flag = [0] * N
    red_flag[0] = 1
    for from_box, to_box in proc_list:
        if red_flag[from_box] == 1:
            if counter[from_box] == 1:
                red_flag[from_box] = 0
            red_flag[to_box] = 1
        counter[from_box] -= 1
        counter[to_box] += 1
    print(sum(red_flag))


if __name__ == '__main__':
    main()

Solution (Python):
n, m = list(map(int, input().split()))
b = [["W", 1] for _ in range(n)]
b[0] = ["R", 1]

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

    b[x-1][1] -= 1
    if b[x-1][0] == "R":
        b[y-1] = ["R", b[y-1][1]+1]

        if b[x-1][1] == 0:
            b[x-1][0] = "W"
    else:
        b[y-1][1] += 1

cnt = 0
for i in range(n):
    if b[i][0] == "R":
        cnt += 1

print(cnt)

Solution (Python):
N, M = map(int, input().split())
x = [0]
y = [0]
memo = [1] * (N + 1) 
flag = [0] * (N + 1) 
for _ in range(M):
    _x, _y = map(int, input().split())
    x.append(_x)
    y.append(_y)

flag[1] = 1
for i in range(1, M + 1):
    if memo[x[i]] == 0: 
        continue
    memo[x[i]] -= 1
    memo[y[i]] += 1
    if flag[x[i]] == 1:
        flag[y[i]] = 1
    if memo[x[i]] == 0:
        flag[x[i]] = 0

ans = 0
for i in range(1, N + 1):
    if memo[i] <= 0:
        continue
    if flag[i] == 1:
        ans += 1


print(ans)

Solution (Python):







def solve(n,m,queries):
  redInBox   = [False] * (n+1)
  amountOfBalls = [1] * (n+1)
  redInBox[1] = True
  
  for query in queries:
    x,y = query
    if redInBox[x]:
      redInBox[y] = True
      amountOfBalls[x] -= 1
      amountOfBalls[y] += 1
      if amountOfBalls[x] == 0:
        redInBox[x] = False
    else:
      amountOfBalls[x] -= 1
      amountOfBalls[y] += 1
 
  return sum(redInBox)



def main():
  N,M = map(int,input().split())
  queries = [list(map(int,input().split())) for _ in range(M)]
  print(solve(N,M,queries))
  return

if __name__ == '__main__':
  main()

Solution (Python):
N,M = map(int, input().split())
red = [0 for i in range(N)]
cnt = [1 for i in range(N)]
red[0] = 1
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x] > 0:
        if cnt[x] >= 2:
            cnt[x] -= 1
            cnt[y] += 1
            red[y] = 1
        else:
            cnt[x] -= 1
            cnt[y] += 1
            red[x] = 0
            red[y] = 1
    else:
        cnt[x] -= 1
        cnt[y] += 1

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

print(ans)

Solution (Python):
n,m=map(int, input().split())
ball=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
    x, y=map(int, input().split())
    x-=1
    y-=1
    ball[x]-=1
    ball[y]+=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())
prob = [False] * (n + 1)
exact = [False] * (n + 1)
prob[1] = exact[1] = True
num_in = [1] * (n + 1)
for _ in range(m):
    x, y = map(int, input().split())
    if num_in[x] == 1 and exact[x]:
        exact[y] = True
        exact[x] = False
        prob[x] = False
        prob[y] = True
    elif num_in[x] > 1 and exact[x]:
        exact[x] = False
        prob[y] = True
    elif prob[x]:
        if num_in[x] == 1:
            prob[x] = False
        prob[y] = True
    num_in[y] += 1
    num_in[x] -= 1
print(prob.count(True))

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

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

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

cnt = 0
for i in range(n):
    if flag[i] == True and balls[i]>=1:
        cnt += 1
print(cnt)

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))





def main():
	n,m=MI()
	
	A=[1]*(n+1)
	B=[0]*(n+1)
	B[1]=1
	
	for _ in range(m):
		x,y=MI()
		A[x]-=1
		A[y]+=1
		
		if B[x]==1:
			B[y]=1
		if A[x]==0:
			B[x]=0

	print(sum(B))
	
	
	
	
	
	
	
	
	
	








	
	
	

if __name__=="__main__":
	main()

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

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

p=[1]*n
c=['w']*n
c[0]='r'


def ope(x,y):
    if c[x-1]=='r':
        c[y-1]='r'
    p[x-1] -= 1
    p[y-1] += 1
    if p[x-1]==0:
        c[x-1]='w'

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


print(c.count('r'))

Solution (Python):

import sys
input = sys.stdin.buffer.readline

n, m = [int(i) for i in input().split()]

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

ans = sum(have_red)

print(ans)

Solution (Python):
N, M = map(int, input().split())
Z = [list(map(int,input().split())) for i in range(M)]
kosuu = [1 for _ in range(N)]
red = [False for _ in range(N)]
red[0] = True

for i in range(M):
  x = Z[i][0] - 1
  y = Z[i][1] - 1
  if (kosuu[x] != 0 and red[x] == True):
    red[y] = True
  if (kosuu[x] == 1 and red[x] == True):
    red[x] = False
  kosuu[x] -= 1
  kosuu[y] += 1

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

print(ans)

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

Solution (Python):



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

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()
red = [False] * n
red[0] = True
box = [1] * n
for i in range(m):
    x,y = map(lambda x:int(x)-1, input().split())
    box[x] -= 1
    box[y] += 1
    if red[x]:
        red[y] = True
    if box[x] == 0:
        red[x] = False
cnt = 0
for i in range(n):
    if red[i]:
        cnt += 1
print(cnt)

Solution (Python):




n, m = map(int,input().split())
rlist = [0] * (n+1)
wlist = [1] * (n+1) 
rlist[1] = 1
wlist[1] = 0


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

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


print(ans)