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



Sample input:
3 2
1 2
2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()
data = ILL(M)
count = [1 for i in range(N)]
p = [0 for i in range(N)]
p[0] = 1000000000000000000000
for x,y in data:
  x,y = x-1,y-1
  if count == 1:
    p[x],p[y] = 0, p[y] + p[x]
  else:
    N = count[x]
    p[x],p[y] = p[x]*(1-1/N), p[y]+p[x]/N
  count[x] -= 1
  count[y] += 1
ans = 0
for i in p:
  if i!=0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()
data = ILL(M)
count = [1 for i in range(N)]
p = [0 for i in range(N)]
p[0] = 1
for x,y in data:
  x,y = x-1,y-1
  if count == 1:
    p[x],p[y] = 0, p[y] + p[x]
  else:
    N = count[x]
    p[x],p[y] = p[x]*(1-1/N), p[y]+p[x]/N
  count[x] -= 1
  count[y] += 1
ans = 0
for i in p:
  if i!=0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
possibility = [0 for _ in range(n)]
ball = [1 for _ in range(n)]
possibility[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    if ball[x-1] != 0:
        possibility[y-1] = 1
    ball[x-1] -= 1
    ball[y-1] += 1
print(np.sum(np.array(possibility) > 0))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
probability = [0 for _ in range(n)]
ball = [1 for _ in range(n)]
probability[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    prob = probability[x-1]
    probability[x-1] = prob * (ball[x-1] - 1) / ball[x-1]
    probability[y-1] += prob / ball[x-1]
    ball[x-1] -= 1
    ball[y-1] += 1
print(np.sum(np.array(probability) > 0))

Submission status: Wrong Answer

Solution code:
import sys


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


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

red = [0]*N
box = [1]*N
red[0] = 1
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

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

print(red.count(1))

Submission status: Wrong Answer

Solution code:
import sys


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


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

red = [0]*N
box = [1]*N
red[0] = 1
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    if red[x] == 1:
        if box[x] == 1:
            red[x] = 0
            box[x] -= 1
            box[y] += 1
            red[y] = 1
        elif box[x] >= 2:
            box[x] -= 1
            box[y] += 1
            red[y] = 1

print(red.count(1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  7 14:28:00 2020

@author: NEC-PCuser
"""

N, M = map(int, input().split())
x, y = [], []

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

box = [1] * N 
ball_set = set()
ball_set.add(1)
start_flg = True
for i in range(len(x)):
    ball_set.add(y[i])
    box[x[i] - 1] -= 1
    box[y[i] - 1] += 1
    if box[x[i] - 1] == 0:
        ball_set.discard(x[i])

print(len(ball_set))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  7 14:28:00 2020

@author: NEC-PCuser
"""

N, M = map(int, input().split())
x, y = [], []

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

box = [1] * N 
ball_set = set()
ball_set.add(1)
start_flg = True
for i in range(len(x)):
    box[x[i] - 1] -= 1
    box[y[i] - 1] += 1
    if x[i] in ball_set:
        if start_flg == True:
            ball_set.discard(1)
            start_flg == False
        if box[x[i] - 1] == 0:
            ball_set.discard(x[i])
        ball_set.add(y[i])
    if y[i] == 1 and start_flg == True:
        start_flg == False
    

print(len(ball_set))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  7 14:28:00 2020

@author: NEC-PCuser
"""

N, M = map(int, input().split())
x, y = [], []

for i in range(M):
    x_tmp, y_tmp = map(int, input().split())
    x.append(x_tmp)
    y.append(y_tmp)
    
ball_set = set()
ball_set.add(1)
start_flg = True
for i in range(len(x)):
    if x[i] in ball_set:
        if start_flg == True:
            ball_set.discard(1)
        ball_set.add(y[i])
        

print(len(ball_set))

Submission status: Wrong Answer

Solution code:
import numpy as np   
n,m = [int(i)for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

line = np.array([1 for _ in range(n)])
is_red = np.zeros(n,dtype = np.int32)
is_red[0] = 1

for x,y in l:
    line[x] -= 1 if line[x] > 0 else 0
    line[y] += 1
    is_red[y] = 1 if is_red[x] == 1 else is_red[y] if line[x] > 0 else 0
    

ans = np.count_nonzero(is_red[line > 0])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np   
n,m = [int(i)for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

line = np.array([1 for _ in range(n)])
is_red = np.zeros(n,dtype = np.int32)
is_red[0] = 1

for x,y in l:
    line[x] -= 1 if line[x] > 0 else 0
    line[y] += 1
    is_red[y] = 1 if is_red[x] == 1 else is_red[y]
    

ans = np.count_nonzero(is_red[line > 0])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np   
n,m = [int(i)for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

line = np.array([1 for _ in range(n)])
is_red = np.zeros(n,dtype = np.int32)
is_red[0] = 1

for x,y in l:
    line[x] -= 1 if line[x] > 0 else 0
    line[y] += 1
    is_red[y] = 1 if is_red[x] == 1 else 0
    

ans = np.count_nonzero(is_red[line > 0])

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    
    s[y-1] = s[x-1]
    s[x-1] = int(b[x-1] == 1)

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

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1

    s[y-1] = int(s[x-1] == 1)
    s[x-1] = int(b[x-1] != 0)

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1

    s[y-1] = int(b[x-1] != 0)
    s[y-1] = int(s[x-1] == 1)

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1

    s[x-1] = int(b[x-1] != 0)
    s[y-1] = int(s[x-1] == 1)

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1

    s[x-1] = int(b[x-1] != 0)
    s[y-1] = s[x-1]

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1

    s[x-1] = int(b[x-1] != 0)
    s[y-1] = s[x-1]

print(sum(s))

Submission status: Wrong Answer

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

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    b[x-1] -= 1
    b[y-1] += 1
    if s[x-1] == 1 and s[y-1] == 0:
        s[x-1] = int(b[x-1] != 0)
        s[y-1] = 1

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

a = [[1, False] for _ in range(n+1)]
a[1] = [1, True]

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

print(sum(x[1] for x in a))

Submission status: Wrong Answer

Solution code:
N,M = [int(hoge) for hoge in input().split()]
Ball = [False]*N
BallNum = [1] * N
Ball[0] = True
for i in range(M):
    x,y = [int(hoge) - 1  for hoge in input().split()]
    BallNum[x] -= 1
    BallNum[y] += 1
    Ball[y] = Ball[x]
    if BallNum[x] == 0:
        Ball[x] = False
print(sum(Ball))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
box = [[1,0] for i in range(n)]#個数、赤の可能性
box[0][1] = 1
ans = 1

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

kotae = 0
for i in range(n):
    kotae += box[i][1]
print(kotae)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
box = [[1,0] for i in range(n)]#個数、赤の可能性
box[0][1] = 1
ans = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
box = [[1,0] for i in range(n)]#個数、赤の可能性
box[0][1] = 1
ans = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
ans = [0 for _ in range(n)]
bal = [1 for _ in range(n)]
ans[0] = 0
for _ in range(m):
    x, y = MAP()
    bal[x - 1] -= 1
    bal[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if not bal[x - 1]:
            ans[x - 1] = 0
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
ans = [0 for _ in range(n)]
ans[0] = 0
for _ in range(m):
    x, y = MAP()
    if ans[x - 1] == 1:
        ans[y - 1] = 1
print(sum(ans))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x_li = [0]*m
y_li = [0]*m
for i in range(m):
    x_li[i],y_li[i]=map(int,input().split())

map_li = [[0,1] for i in range(n)]#[W,R]
map_li[0]=[1,0]

for i in range(m):
    x,y = x_li[i],y_li[i]
    x,y = x-1,y-1
    if map_li[x][0]>0:
        map_li[x][0]-=1
        map_li[y][0]+=1
    else:
        map_li[x][1]-=1
        map_li[y][1]+=1
print(sum(l[1]!=0 for l in map_li))

Submission status: Wrong Answer

Solution code:
n , m = map(int,input().split())
aka = [False for i in range(n+1)]
siro = [1 for i in range(n+1)]
aka[1] = True
siro[1] = 0
for i in range(m):
    x , y = map(int,input().split())
    if aka[x]:
        if siro[x] >= 1:
            siro[x] -= 1
            siro[y] += 1
        elif siro[x] == 0:
            aka[x] = False
        aka[y] = True
    elif not aka[x]:
        siro[x] -= 1
        siro[y] += 1
ans = 0
for i in range(1,n+1):
    if aka[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

lisN = [0] + [1]*N
ansSet = set([1])

for _ in range(M):
    # print(ansSet,lisN)
    x,y = map(int,input().split())
    if x in ansSet:
        ansSet.add(y)
        lisN[x] -= 1
        lisN[y] += 1

for i,v in enumerate(lisN):
    if v == 0:
        ansSet.discard(i)

print(len(ansSet))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
boxes = [[0, 1] for _ in range(n)]
boxes[0][0] = 1
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    boxes[x][1] -= 1
    boxes[y][1] += 1
    if boxes[x][0] == 1:
        boxes[y][0] = 1
    else:
        if boxes[y][0] == 1:
            continue
        else:
            boxes[y][0] = 0  
    if boxes[x][1] == 0:
        boxes[x][0] = -1
ans = 0
for a, b in boxes:
    # print(a, b)
    if a:
        ans += 1
# print(boxes)
print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    if xy[i][0] == 1:
        break
else:
    print(1)
    exit()

hako = [1]*(n+1)
iti = False
hituyou = {1}
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]

    hako[x] -= 1
    hako[y] += 1
    if x in hituyou:
        if y != 1:
            hituyou.add(y)
        else:
            iti = True
hituyou = list(hituyou)
if iti == False:
    hituyou.remove(1)
ans = 0
for i in range(len(hituyou)):
    if hako[hituyou[i]] > 0:
        ans += 1
print(ans)
#print(hako,hituyou)

Submission status: Wrong Answer

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

for i in range(m):
    if xy[i][0] == 1:
        break
else:
    print(1)
    exit()

hako = [1]*(n+1)
iti = False
hituyou = {1}
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]

    hako[x] -= 1
    hako[y] += 1
    if x in hituyou:
        if y != 1:
            hituyou.add(y)
        else:
            iti = True
hituyou = list(hituyou)
if iti == False:
    hituyou.remove(1)
ans = 0
for i in range(len(hituyou)):
    if hako[hituyou[i]] > 0:
        ans += 1
print(ans)
print(hako,hituyou)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
xy = []
for i in range(m):
    xy.append(list(map(int,input().split())))

hako = [1]*(n+1)
iti = False
hituyou = {1}
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]

    hako[x] -= 1
    hako[y] += 1
    if x in hituyou:
        if y != 1:
            hituyou.add(y)
        else:
            iti = True
hituyou = list(hituyou)
if iti == False:
    hituyou.remove(1)
ans = 0
for i in range(len(hituyou)):
    if hako[hituyou[i]] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def mov(xy,N):
    Box_red = set([xy[0][1]])
    Box = [1 for _ in range(N)]

    for i in range(len(xy)):
        Box[xy[i][0]-1] -= 1
        Box[xy[i][1]-1] += 1
        if xy[i][0] in Box_red:
            Box_red.add(xy[i][1])
        if Box[xy[i][0]-1] == 0:
            Box_red.discard(xy[i][0])

    return len(Box_red)

def main():
    N,M = map(int,input().split())
    xy = [list(map(int,input().split())) for _ in range(M)]
    ans = mov(xy,N)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = [1] * (n)
ans[0] = 1
ball = {0}
for i in range(m):
    x, y = xy[i]
    if (x - 1) in ball:
        ans[y-1] += 1
        ans[x-1] -= 1
        ball.add(y - 1)
    if ans[x-1] == 0:
      ball -= set([x-1])

cnt = 0
for i in list(ball):
  if ans[i] > 0:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


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

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if red[x] > 0:
            red[x] -= 1
            red[y] = white[y]+1
            white[y] = 0
        else:
            white[x] -= 1
            white[y] += 1
    ans = 0
    for j in range(N):
        if red[j] > 0:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

print(res)

Submission status: Wrong Answer

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

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

for i in range(m):
	x, y = XY[i]
	x -= 1
	y -= 1
	if Ball[x] >= 1:
		if Done[y] == False:
			Ball[x] -= 1
			Ball[y] = 2
			Done[y] = True
		else:
			Ball[x] -= 1
			Ball[y] += 1

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

print(res)

Submission status: Wrong Answer

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


ans=0

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

print(ans)

Submission status: Wrong Answer

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

ans=0

for i in range(n):
    if ball[i]==0:
        check[i]=False

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

print(ans)

Submission status: Wrong Answer

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

ans=0

for i in range(n):
    if ball[i]==0:
        check[i]=False

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

print(ans)