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())
white = [1]*n
white[0] = 0
red = [0] * n
red[0] = 1

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

    if red[x] > 0:
        red[y] += 1
    else:
        white[y] += 1

    if white[x] > 0:
        white[x] -= 1
    else:
        red[x] -= 1


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

Solution (Python):
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

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

for i in li:
    ball[i[0]] -= 1
    ball[i[1]] += 1
    if red[i[0]] == 1:
        if ball[i[0]] == 0:
            red[i[0]] = 0
        red[i[1]] = 1

print(sum(red))

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

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


arr = [1 for _ in range(n)]
arr1 = [False for _ in range(n)]
arr1[0]=True
ch1 = True

for i in range(m):
    x,y = map(int,input().split())
    x = x-1
    y = y-1
    if ch1 == True and x == 0:
        ch1 = None
        arr[y] +=1
        arr1[y] = True
        arr[x] -=1
        if arr[x] == 0:
            arr1[x] = False
        continue
    
    arr[y] +=1
    arr[x] -=1
    if ch1 == None and arr1[x] == True:
        
        arr1[y] = True
        
    if ch1 == None and arr[x] == 0:
        arr1[x] = False

cnt=0
for i in range(n):
    if arr1[i] == True:
        cnt +=1   
print(cnt)

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

print(sum([flag for flag, _ in XY]))

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

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

cnt = [1] * n
r = [1] + [0] * (n-1)
for x, y in xy:
    cnt[x-1] -= 1
    cnt[y-1] += 1
       
    if r[x-1] == 1:
        r[y-1] = 1
        
    if cnt[x-1] == 0:
        r[x-1] = 0
    
print(sum(r))

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

Solution (Python):
import math

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

    boxes = []
    for i in range(N):
        if i == 0:
            boxes.append([1, True])
        else:
            boxes.append([1, False])

    

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

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

    
    ans = 0
    for c, b in boxes:
        if b:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N, M = map(int, input().split())
n_list = [1 for i in range(N)]
bool_list = [True]
for i in range(N - 1):
    bool_list.append(False)

def move(n_bef, n_aft, bool_bef, bool_aft):
    n_bef -= 1
    n_aft += 1

    if bool_bef:
        bool_aft = True

        if n_bef == 0:
            bool_bef = False
    
    return [n_bef, n_aft, bool_bef, bool_aft]

for i in range(M):
    x, y = map(int, input().split())
    n_list[x - 1], n_list[y - 1], bool_list[x - 1], bool_list[y - 1] = move(n_list[x - 1], n_list[y - 1], bool_list[x - 1], bool_list[y - 1])

ans = 0
for bool_ in bool_list:
    if bool_:
        ans += 1

print(ans)

Solution (Python):

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

ans = list(filter(lambda x: x == True, reddable))
print(len(ans))

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

Solution (Python):
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())
   x[i]-=1
   y[i]-=1
isRed = [False] * N
isRed[0] = True
cnt = [1] * N
for i in range(M):
   cnt[y[i]]+=1
   if(isRed[x[i]]):
      isRed[y[i]] = True
   cnt[x[i]]-=1
   if(cnt[x[i]] == 0):
      isRed[x[i]] = False
ans = 0
for i in range(N):
   if(isRed[i]):
      ans+=1
print(ans)

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

red = [0 for _ in range(N)]
red[0] = 1
num = [1 for _ in range(N)]

for o in operation:
    num[o[0]-1] -= 1
    num[o[1]-1] += 1
    if red[o[0]-1]:
        if num[o[0]-1] == 0:
            red[o[0]-1] = 0
        red[o[1]-1] = 1
    
print(sum(red))

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

Solution (Python):
n,m=map(int,input().split())
a=[1]*n
ans=set([1])
for i in range(m):
  x,y=map(int,input().split())
  if a[x-1]==0:continue
  else:
    a[x-1]-=1
    a[y-1]+=1
    if x in ans:
      ans.add(y)
      if a[x-1]==0:ans.remove(x)
print(len(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())
    
    if(b[x]==1):
        b[y] = 1
    
    a[x]-=1
    a[y]+=1
    
    if(a[x]==0):
        b[x] = 0
    
cn = 0    

for i in range(1,n+1):
    if(b[i]==1 and a[i]>0):
        cn += 1
        
print(cn)

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

p = [0] * N
p[0] = 1
ball = [1] * N

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

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

print(ans)

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

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

print(sum(red))

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

Solution (Python):
N,M = map(int,input().split())
x = []
y = []
for i in range(M):
    x_i,y_i = map(int,input().split())
    x.append(x_i)
    y.append(y_i)

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


for i in range(M):
    box_c[x[i]] -= 1
    box_c[y[i]] += 1
    
    if box_r[x[i]]==1:
        box_r[y[i]] = 1
        if box_c[x[i]]==0:
            box_r[x[i]] = 0
   
print(box_r.count(1))

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

num_b = [1 for i in range(N+1)]
num_b[0] = 0
psb = [0]*(N+1)
psb[1] = 1
for i in range(M):
    num_b[X[i][0]] -= 1
    num_b[X[i][1]] += 1
    if psb[X[i][0]] == 1:
        psb[X[i][1]] = 1 
    if num_b[X[i][0]] == 0:
        psb[X[i][0]] = 0

print(psb.count(1))

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

num_b = [1 for i in range(N+1)]
num_b[0] = 0
psb = [0]*(N+1)
psb[1] = 1
for i in range(M):
    num_b[X[i][0]] -= 1
    num_b[X[i][1]] += 1
    if psb[X[i][0]] == 1:
        psb[X[i][1]] = 1 
    if num_b[X[i][0]] == 0:
        psb[X[i][0]] = 0

print(psb.count(1))

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

Solution (Python):

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    xy = map(int, sys.stdin.read().split())
    xy = zip(xy, xy)

    count = dict((i, 1) for i in range(1, n+1))
    may_contain_red = set([1])

    for x, y in xy:
        count[x] -= 1; count[y] += 1
        if x in may_contain_red:
            may_contain_red.add(y)
            if count[x] == 0:
                may_contain_red ^= set([x])
    
    ans = len(may_contain_red)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from collections import deque

def main():
    n, m = map(int, sys.stdin.readline().split())
    xy = map(int, sys.stdin.read().split())
    xy = zip(xy, xy)


    count = dict((i, 1) for i in range(1, n+1))
    may_contain_red = set([1])

    for x, y in xy:
        count[x] -= 1; count[y] += 1
        if x in may_contain_red:
            may_contain_red.add(y)
            if count[x] == 0:
                may_contain_red -= set([x])
    
    ans = len(may_contain_red)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(M)]
s = [1] * N
a = [0] * N
a[0] = 1
for i in range(M):
    s[x[i][0] - 1] -= 1
    if a[x[i][0] - 1] == 1:
        a[x[i][1] - 1] = 1
        if s[x[i][0] - 1] == 0:
            a[x[i][0] - 1] = 0
    s[x[i][1] - 1] += 1


print(sum(a))

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



box = [[1,0] for i in range(N)] 
box[0][1] = 1

for x,y in transferlist:
    box[x][0] -=1
    box[y][0] += 1
    if box[x][1] == 1:
        box[y][1] = 1
    if box[x][0] == 0:
        box[x][1] = 0

ans = sum(i[1] for i in box)
print(ans)

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

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

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

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

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

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

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

b = [1] * N
b[0] = -1
for i in range(M):
  x, y = map(int, input().split())
  if b[x - 1] < 0:
    b[x - 1] += 1
    b[y - 1] = -(abs(b[y - 1]) + 1)
  else:
    b[x - 1] -= 1
    if b[y - 1] < 0:
      b[y - 1] -= 1
    else:
      b[y - 1] += 1
print(len([x for x in b if x < 0]))

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

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

for i in range(M):
    X,Y=map(int,input().split())
    if(L[X][0]!=0):
        L[X][0]-=1
        L[Y][0]+=1
        if(L[X][1]!=0):
            L[Y][1]=1
            if(L[X][0]==0):
                 L[X][1]=0

t=0
for i in range(N+1):
    t+=L[i][1]
print(t)

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

box = [1 for i in range(n)]
red = [0 if i != 0 else 1 for i in range(n)]

for xy in move:
    x,y = xy

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

    if red[x-1] is 1: red[y-1] = 1
    if box[x-1] is 0: red[x-1] = 0

print(sum(red))

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

c = [1] * n
bl = [False] * n
bl[0] = True

for _ in range(m):
    x, y = (int(j) - 1 for j in input().split())
    c[x] -= 1
    c[y] += 1
    if bl[x]:
        if c[x] == 0:
            bl[x] = False
        bl[y] = True
    
print(bl.count(True))

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

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

N, M = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(M)]
b = [1] * N
p = [0] * (N + 1)
p[1] = 1
for move in m:
  b[move[0] - 1] -= 1
  b[move[1] - 1] += 1
  p[move[1]] += p[move[0]]
  if b[move[0] - 1] == 0:
    p[move[0]] = 0
res = 0
for i in range(N):
  if p[i + 1] > 0 and b[i] > 0:
    res += 1
print(res)

Solution (Python):


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

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

red_box_dict = {i: False for i in range(1, N + 1)}
red_box_dict[1] = True


n_box_list = [0] + [1] * N

for xy in xy_table:
    x, y = xy
    n_box_list[x] -= 1
    n_box_list[y] += 1
    if red_box_dict[x]:
        red_box_dict[y] = True

        if n_box_list[x] == 0:
            red_box_dict[x] = False

ans = len([v for v in red_box_dict.values() if v])

print(ans)

Solution (Python):
import collections
N, M = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(M)]
table = collections.defaultdict(int)
table2 = collections.defaultdict(int)
table2[1] += 1

for i in range(N):
    table[i+1] = 1
reached = [1]
for i in range(M):
    table[xy[i][1]] += 1
    table[xy[i][0]] -= 1
    if xy[i][0] in table2 and table2[xy[i][0]] > 0:
        table2[xy[i][0]] = table[xy[i][0]]
        table2[xy[i][1]] += table[xy[i][1]] + 1

table2 = list(table2.items())
table2 = [x for x in table2 if x[1] > 0]
print(len(table2))

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

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

for x, y in zip(xy, xy):
    if red[x]:
        red[y] = True

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

    if ball[x] == 0:
        red[x] = False

print(sum(red[1:]))

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

Solution (Python):


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

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

for i in range(M):

    x,y = map(int,input().split())

    x -= 1
    y -= 1

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

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

    if num[x] == 0:
        lis[x] = False

ans = 0

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

print (ans)

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

red = [True] + [False] * (N - 1)
total = [1] + [1] * (N - 1)
ans = 1
for i in range(M):
    xi, yi = map(int, input().split())
    if red[xi - 1]:
        red[yi - 1] = True
    total[xi - 1] -= 1
    total[yi - 1] += 1
    if total[xi - 1] == 0:
        red[xi - 1] = False
print(red.count(True))

Solution (Python):
N,M=map(int,input().split())
XY=[list(map(int,input().split())) for i in range(M)]
borldata=[1 for i in range(N)]
akaidxlist=[0 for i in range(N)]
akaidxlist[0]=1
for i in XY:
    x,y=i
    x,y=x-1,y-1
    if akaidxlist[x]==1:
        akaidxlist[y]=1
        if borldata[x]==1:akaidxlist[x]=0
    borldata[x]-=1
    borldata[y]+=1
print(len([i for i in akaidxlist if i]))

Solution (Python):
n,m = map(int,input().split())
a = [[int(i) for i in input().split()] for i in range(m)]
p=["f"]*n
p[0]="t"
q=[1]*n
for i in range(0,m):
  q[a[i][0]-1]-=1
  q[a[i][1]-1]+=1
  if p[a[i][0]-1]=="t":
    p[a[i][1]-1]="t"
    if q[a[i][0]-1]==0:
      p[a[i][0]-1]="f"
print(p.count("t"))

Solution (Python):
import sys
N, M = map(int, input().split())
P = [[int(v) - 1 for v in sys.stdin.readline().split()] for _ in range(M)]

L = [(1, True)] + ([(1, False)] * (N - 1))

for x, y in P:
    ac, ad = L[x]
    bc, bd = L[y]
    ac -= 1
    bc += 1
    if ad:
        bd = True
    if ac == 0:
        ad = False
    L[x] = (ac, ad)
    L[y] = (bc, bd)

print(sum([f for _, f in L]))

Solution (Python):





mod=10**9+7
def factorial(x): 
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): 
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): 
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    
    
    
    
    
    
    
    
    
    
    n,m = map(int,input().split())
    p=[0 for _ in range(n)]
    box=[1 for _ in range(n)]
    p[0]=1
    for _ in range(m):
        a,b=map(int,input().split())
        if p[a-1]==1 and box[a-1]==1:
            p[b-1]=1
            p[a-1]=0
            box[a-1]-=1
            box[b-1]+=1
        elif p[a-1]==1 and box[a-1]!=1:
            p[b-1]=1
            p[a-1]=1
            box[a-1]-=1
            box[b-1]+=1
        else:
            box[a-1]-=1
            box[b-1]+=1
    print(sum(p))
main()

Solution (Python):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
red = [False]*(N+1)
red[1] = True
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        red[x] = False
ans = 0
for i in red:
    if i:
        ans += 1
print(ans)

Solution (Python):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
red = [False]*(N+1)
red[1] = True
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        red[x] = False
ans = 0
for i in red:
    if i:
        ans += 1
print(ans)

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

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

print(sum(bt))

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

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n,m = inpl()
xy = [0] * m
ball = [1] * n
check = [False] * n
check[0] = True
fl = True
res = 0
for i in range(m):
    x,y = inpl()
    ball[x-1] -= 1
    ball[y-1] += 1
    if check[x-1] == True:
        check[y-1] = True
    if ball[x-1] == 0 and check[x-1]:
        check[x-1] = False
print(check.count(True))

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

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

print(sum(red))

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

li=[1]*(n+1)

se=set()
se.add(1)
for  i in range(m):
	x,y=map(int,input().split())
	li[x]-=1
	li[y]+=1
	if x in se:
		se.add(y)
		if li[x]==0:
			se.remove(x)
print(len(se))

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


def main():
    N, M = map(int, input().split())

    A = [0]*N
    A[0] = 1
    B = [1]*N
    for q in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if A[x] == 1:
            A[y] = 1
        B[x] -= 1
        B[y] += 1
        if B[x] == 0:
            A[x] = 0

    ans = 0
    for i in range(N):
        if A[i] == 1 and B[i] != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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


def main():
    N, M = map(int, input().split())

    A = [0]*N
    A[0] = 1
    B = [1]*N
    for q in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if A[x] == 1:
            A[y] = 1
        B[x] -= 1
        B[y] += 1
        if B[x] == 0:
            A[x] = 0

    ans = 0
    for i in range(N):
        if A[i] == 1 and B[i] != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

lis = [1] * 10 ** 5
ind_red = [False] * 10 ** 5
ind_red[0] = True
for m in range(M):
    x, y = map(int, input().split())
    if ind_red[x - 1] and lis[x - 1] >= 2:
        ind_red[y - 1] = True
    elif ind_red[x - 1] and lis[x - 1] < 2:
        ind_red[y - 1] = True
        ind_red[x - 1] = False
    lis[x - 1] -= 1
    lis[y - 1] += 1
print(sum(ind_red))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=[0]*n
  l2=[1]*n

  l[0]=1

  for _ in range(m):
    x,y=LI()
    l2[y-1]+=1
    l2[x-1]-=1

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

      if l2[x-1]==0:
        l[x-1]=0

  sm=0
  for x in l:
    if x>0:
      sm+=1
  return sm


print(main())

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

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

print(cnt)

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


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

red=[False for i in range(N+1)];red[1]=True

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

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

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

ans = sum(red)
print(ans)

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

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

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

Solution (Python):
N, M = input().split()
N, M = [int(N), int(M)]
x = [None] * (M+1)
y = [None] * (M+1)

for i in range(1, M+1):
    x[i], y[i] = input().split()
    x[i], y[i] = [int(x[i]), int(y[i])]

R = [0] + [1] + [0] * (N-1) 
S = [0] + [1] * (N) 

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

    if R[x[i]] == 1:
        R[y[i]] = 1
        if S[x[i]] == 0:
            R[x[i]] = 0

sum = 0
for i in range(1, N+1):
    sum += R[i]

print(sum)

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


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

for x, y in transfer:
    
    
    balls[x][0] -= 1
    balls[y][0] += 1
    if balls[x][1] == 1:
        balls[y][1] = 1
        if balls[x][0] == 0:
            balls[x][1] = 0


print(len(list(filter(lambda x: x[1] == 1, balls))))

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

red[0] = True

for x, y in XY:
  if red[x -1] == True and num[x - 1] > 0:
    red[y - 1] = True
  num[x - 1] -= 1
  num[y - 1] += 1
  if num[x - 1] == 0:
    red[x - 1] = False

cnt = 0
for i, j in zip(red, num):
  if i == True and j > 0:
    cnt += 1
    

print(cnt)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
ball_num = [1] * n
red_exist = [0] * n
red_exist[0] = 1
flag = False
red_box = 0
for _ in range(m):
    x, y = LI()
    ball_num[x - 1] -= 1
    ball_num[y - 1] += 1
    if red_exist[x - 1]:
        red_exist[y - 1] = 1
    if ball_num[x - 1] == 0:
        red_exist[x - 1] = 0




cnt = 0
for i in range(n):
    if red_exist[i] and ball_num[i]:
        cnt += 1


print(cnt)

Solution (Python):
import sys
import os

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


box = [[0,1] for _ in range(N)]
box[0] = [1,1]
move = [0 for _ in range(M)]
for i in range(M):
    s,t = map(int,input().split())
    move[i] = [s-1,t-1]
for i in range(M):
    box[move[i][0]][1] -= 1
    box[move[i][1]][1] += 1
    if box[move[i][0]][0] == 1:
         box[move[i][1]][0] = 1
    if box[move[i][0]][1] == 0:
        box[move[i][0]][0] = 0
cnt = 0
for b in box:
    if b[0] == 1:
        cnt += 1
print(cnt)

Solution (Python):
import numpy as np
n, m= map(int , input().split())
xy=[list(map(int,input().split())) for _ in range(m)]
count=[1]*n
ans=[True]+[False]*(n-1)
f=True
for i in range(m):
    if ans[xy[i][0]-1]== True:
        ans[xy[i][1]-1]=True
        if count[xy[i][0]-1]==1:
            ans[xy[i][0]-1]=False
    count[xy[i][0]-1]-=1
    count[xy[i][1]-1]+=1

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

print(answer)