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:
n,m=map(int,input().split())
check=[False]*n
check[0]=True
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if check[x]:
        check[y]=True
    else:
        continue

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

print(ans)

Submission status: Wrong Answer

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

ans=0

for i in range(n):
    if check[i]:
        ans+=1

print(ans-1)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

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

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    # 数が入っているのと、
    # 箱の中が0かどうかを判別するものを定義する
    # 全部まず1個入ってる
    nums = [1] * n
    In = [True] * n
    for i in range(m):
        a,b = map(lambda x:int(x) - 1, input().split())
        nums[a] -=1
        nums[b] +=1
        if nums[a] == 0:
            In[a] = False
        if nums[a] != 0:
            In[a] = True
        if nums[b] != 0:
            In[b] = True
    cnt = 0
    for i in range(n):
        if In[i]:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

    if ans[a-1]==0 and v[a-1]:
        if v[b-1]:fi-=1
        else:v[b-1]=1
    if ans[a-1]>0 and v[a-1]:
        fi+=1
        v[b-1]=1

print(fi)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(bit_l.count(1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
a = [1]+[0]*(N-1)
b = [1]*N
sts = 0

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

  if x ==1 and sts == 0:
    a[x-1]=0
    a[y-1]=1
    sts+=1
  elif a[x-1]==1 and b[x-1]==1:
    a[x-1]=0
    a[y-1]=1
  elif a[x-1]==1:
    a[y-1]=1
  b[x-1]-=1
  b[y-1]+=1
    
print(sum(a))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
a = [1]
b = [1]*N

for i in range(M):
  x,y = map(int,input().split())
  b[x-1]-=1
  b[y-1]+=1
  if x ==1 and a == [1]:
    a.remove(1)
    a.append(int(y))
  elif (x in a) and (y not in a):
    a.append(int(y))
    
ans=0

for j in range(len(a)):
  if b[a[j]-1]!=0:
    ans+=1

print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N) 
dp = [1] * N
for i in range(M):
    xi,yi = map(int, input().split())
    xi-=1
    yi-=1
    dp[xi] -= 1
    dp[yi] += 1
    if not uf.judge(xi,yi):
        uf.union(xi,yi)
        
ans = 0
p = uf.find(0)
for i  in range(1,N):
    if uf.find(i) == p and dp[i] != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(m)]
box=[[1,0]]
for i in range(n-1):
    box.append([0,1])
for x,y in li:
    tmp=box[x-1].copy()
    box[x-1][0]-=tmp[0]/(tmp[0]+tmp[1])
    box[x-1][1]-=tmp[1]/(tmp[0]+tmp[1])
    box[y-1][0]+=tmp[0]/(tmp[0]+tmp[1])
    box[y-1][1]+=tmp[1]/(tmp[0]+tmp[1])
ans=0
for i in box:
    if i[0]>0.01:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(m)]
box=[[1,0]]
for i in range(n-1):
    box.append([0,1])
for x,y in li:
    tmp=box[x-1].copy()
    box[x-1][0]-=tmp[0]/(tmp[0]+tmp[1])
    box[x-1][1]-=tmp[1]/(tmp[0]+tmp[1])
    box[y-1][0]+=tmp[0]/(tmp[0]+tmp[1])
    box[y-1][1]+=tmp[1]/(tmp[0]+tmp[1])
ans=0
for i in box:
    if i[0]>0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

r = [1]
d = {x: 1 for x in range(1,n+1)}

for v in xy:
    d[v[0]] -= 1
    d[v[1]] += 1
    if v[0] in r:
        r.append(v[1])
    if d[v[0]] == 0 and v[0] in r:
        r.remove(v[0])

R = set(r)
ans = 0
for x in d.keys():
    if d[x] > 0 and x in R:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, M = map(int, input().split())
    box = [[1, 1]] + [[1, 0] for _ in range(N - 1)]
    for _ in range(M):
        x, y = map(int, input().split())
        x = x - 1
        y = y - 1
        if box[x][0] > 1:
            if box[x][1] > 0:
                r = box[x][1]
                box[x][1] = r - (r / box[x][0])
                box[y][1] += r / box[x][0]
                box[x][0] -= 1
                box[y][0] += 1
            else:
                box[x][0] -= 1
                box[y][0] += 1
        elif box[x][0] == 1:
            if box[x][1] > 0:
                box[y][1] += box[x][1]
                box[x][1] = 0
                box[x][0] = 0
                box[y][0] += 1
            else:
                box[x][0] = 0
                box[y][0] += 1
    answer = 0
    for b in box:
        if b[1] > 0:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    l = []
    red = [1]
    for i in range(M):
        l.append(list(map(int, input().split())))
    for i in range(M):
        if l[i][0] in red:
            red.append(l[i][1])
            red.remove(l[i][0])
    print(len(set(red)))

main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
sift = [list(map(int, input().split())) for _ in range(M)]
ball = [0] * N
ball[0] = 1
num_ball = [1] * N
for i in range(M):
    #print(ball)
    a, b = sift[i]
    a -= 1
    b -= 1
    if ball[a] == 1:
        if num_ball[a] > 1:
            ball[b] = 1
            num_ball[a] -= 1
            num_ball[b] += 1
        else:
            ball[b] = 1
            ball[a] = 0
            num_ball[b] += 1
            num_ball[a] -= 1
print(sum(ball))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
sift = [list(map(int, input().split())) for _ in range(M)]
ball = [0] * N
ball[0] = 1
num_ball = [1] * N
for i in range(M):
    #print(ball)
    a, b = sift[i]
    a -= 1
    b -= 1
    if ball[a] == 1:
        if num_ball[a] > 1:
            ball[b] = 1
            num_ball[a] -= 1
            num_ball[b] += 1
        else:
            ball[b] = 1
            ball[a] = 0
            num_ball[b] += 1
print(sum(ball))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X, Y = [], []

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

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

for x, y in zip(X, Y):
    if red[x] == 1 and ball[x] != 0:
        red[y] = 1
        if ball[x] == 1:
            red[x] = 0
        ball[x] -= 1
        ball[y] += 1

print(sum(red))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X, Y = [], []

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

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

for x, y in zip(X, Y):
    if red[x] == 1 and ball[x] != 0:
        red[y] = 1
        if ball[x] == 1:
            red[x] = 0
            ball[y] += 1
            ball[x] -= 0
        else:
            ball[x] -= 1
            ball[y] += 1

print(sum(red))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
balls = [1 for _ in range(N + 1)]
ans[1] = True
for i in range(M):
  q = list(map(int,input().rstrip().split(" ")))
  if ans[q[0]] == True:
    ans[q[1]] = True
  balls[q[0]] -= 1
  if balls[q[0]] == 0: ans[q[0]] = False
  balls[q[1]] += 1
ansi = 0
print(ans)
for i in range(N + 1):
  if ans[i]: ansi += 1
print(ansi)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
balls = [1 for _ in range(N + 1)]
ans[1] = True
for i in range(M):
  q = list(map(int,input().rstrip().split(" ")))
  if ans[q[0]] == True:
    ans[q[1]] = True
  balls[q[0]] -= 1
  balls[q[1]] += 1
ansi = 0
for i in range(N):
  if ans[i] and balls[i] >= 0: ansi += 1
print(ansi)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

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

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

possibilities = [False] * n
possibilities[0] = True
nums = [1] * n

for i in range(m):
    x = moves[i][0] - 1
    y = moves[i][1] - 1

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

    nums[x] -= 1
    nums[y] += 1
    # if nums[x] == 0:
    #     possibilities[x] = False

ans = 0
for j in range(n):
    if possibilities[j] and (nums[j] > 0):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ans=[]
li=[1 for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    li[x-1]-=1
    li[y-1]+=1
    if i==0:
        if x==1:
            ans.append(y)
    else:
        if x in ans:
            ans.append(y)
cnt=0
for j in set(ans):
    if li[j-1]!=0:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n,m = map(int,input().split())
cnt = [1]*n
visit = [0]*n
visit[0] = 1
for i in range(m):
    x,y = map(int,input().split())
    if visit[x-1] > 0:
        if cnt[x-1] == 1:
            visit[x-1] = 0
        cnt[x-1] -=1
        cnt[y-1] += 1
        visit[y-1] =1
print(sum(1 for i in visit if i > 0))

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
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
red=[2]+[0 for _ in range(1,N)]
num=[1]*N

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

print(len([True for r in red if r==1]))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[]
y=[]
l=[1 for i in range(N+1)]
l[0]=0
chk=[0 for i in range(N+1)]
flag=True
for i in range(M):
    a,b=map(int,input().split())
    if flag:
        if a==1:
            l[a]-=1
            l[b]+=1
            flag=False
            chk[b]=1
        else:
            l[a]-=1
            l[b]+=1
    else:
        if l[a]>0:
            if chk[a]==1:
                l[a]-=1
                l[b]+=1
                chk[b]=1
            else:
                l[a]-=1
                l[b]+=1
            if l[a]==0:
                chk[a]=0
ans=0
for i in range(1,1+N):
    if chk[i]==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[]
y=[]
l=[1 for i in range(N+1)]
l[0]=0
chk=[0 for i in range(N+1)]
flag=True
for i in range(M):
    a,b=map(int,input().split())
    if flag:
        if a==1:
            l[a]-=1
            l[b]+=1
            flag=False
            chk[b]=1
    else:
        if l[a]>0:
            if chk[a]==1:
                l[a]-=1
                l[b]+=1
                chk[b]=1
            else:
                l[a]-=1
                l[b]+=1
            if l[a]==0:
                chk[a]=0
ans=0
for i in range(1,1+N):
    if chk[i]==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[]
y=[]
l=[1 for i in range(N+1)]
l[0]=0
chk=[0 for i in range(N+1)]
flag=True
for i in range(M):
    a,b=map(int,input().split())
    if flag:
        if a==1:
            l[a]-=1
            l[b]+=1
            flag=False
            chk[b]=1
    else:
        if l[a]>0:
            if chk[a]==1:
                l[a]-=1
                l[b]+=1
                chk[b]=1
            else:
                l[a]-=1
                l[b]+=1
ans=0
for i in range(1,1+N):
    if l[i]>0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[]
y=[]
l=[1 for i in range(N+1)]
l[0]=0
chk=[0 for i in range(N+1)]
flag=True
for i in range(M):
    a,b=map(int,input().split())
    if flag:
        if a==1:
            l[a]-=1
            l[b]+=1
            flag=False
            chk[b]=1
    else:
        if l[a]>0:
            if chk[a]==1:
                l[a]-=1
                l[b]+=1
                chk[b]=1
ans=0
for i in range(1,1+N):
    if l[i]>0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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


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

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


print(sum(a[0] > 0 for a in A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
count=[1]*(n+1)
flag=[False]*(n+1)
flag[1]=True
for a,b in arr:
  count[b]+=1
  count[a]-=1
  if flag[a]==True:
    flag[b]==True
  if count[a]==0:
    flag[a]==False
print(flag.count(True))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
count=[1]*(n+1)
s=set()
s.add(1)
for a,b in arr:
  if a in s:
    s.add(b)
    count[b]+=1
    count[a]-=1
  if count[a]==0:
    s.discard(a)
print(len(s))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
data=[]
for i in range(m):
    x,y=map(int,input().split())
    data.append((x,y))
ball=[[1,False] for i in range(n)]
ball[0][1]=True
#一番めのボールは赤色であるため、Trueを返す
for i in range(m):
    x,y=data[i][0],data[i][1]
    #xからyへ
    if ball[x-1][0]==1:
        #x番目のところにボールが一つ入っていた場合
        if ball[x-1][1]==True:
            ball[x-1][0]=0
            ball[y-1][0]+=1
            ball[x-1][1]=False
            ball[y-1][1]=True      
        elif ball[x-1][1]==False:
            ball[x-1][0]=0
            ball[y-1][0]+=1
    elif ball[x-1][0]>=2:
        #x番めのところにボールが二つ入っていた場合
        if ball[x-1][1]==True:
            ball[x-1][0]=1
            ball[y-1][0]+=1
            ball[y-1][1]=True
        elif ball[x-1][1]==False:            
            ball[x-1][0]=1
            ball[y-1][0]+=1
cnt=0
for i in range(n):
    if ball[i][1]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
data=[]
for i in range(m):
    x,y=map(int,input().split())
    data.append((x,y))
ball=[[1,False] for i in range(n)]
ball[0][1]=True
#一番めのボールは赤色であるため、Trueを返す
for i in range(m):
    x,y=data[i][0],data[i][1]
    #xからyへ
    if ball[x-1][0]==1:
        #x番目のところにボールが一つ入っていた場合
        if ball[x-1][1]==True:
            ball[x-1][0]=0
            ball[y-1][0]+=1
            ball[x-1][1]=False
            ball[y-1][1]=True      
        elif ball[x-1][1]==False:
            ball[x-1][0]=0
            ball[y-1][0]+=1
    elif ball[x-1][0]==2:
        #x番めのところにボールが二つ入っていた場合
        if ball[x-1][1]==True:
            ball[x-1][0]=1
            ball[y-1][0]+=1
            ball[y-1][1]=True
        elif ball[x-1][1]==False:            
            ball[x-1][0]=1
            ball[y-1][0]+=1
cnt=0
for i in range(n):
    if ball[i][1]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

gray = [False] * n
gray[0] = True
ball = [1] * n

for x, y in xy:
    x -= 1; y -= 1
    if ball[x] > 0:
        ball[x] -= 1
        ball[y] += 1
        if gray[x]:
            gray[y] = True


ans = 0
for i in range(n):
    if gray[i] and ball[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

gray = [False] * n
gray[0] = True
ball = [1] * n

flag = False
for x, y in xy:
    x -= 1; y -= 1
    if ball[x] > 0:
        ball[x] -= 1
        ball[y] += 1
        if gray[x]:
            gray[y] = True
    if not flag and x == 0:
        flag = True
        gray[y] = True
        ball[x] -= 1
        ball[y] += 1

if flag:
    ans = 0
    for i in range(n):
        if gray[i] and ball[i] > 0:
            ans += 1
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

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

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

flag = False
for x, y in xy:
    x -= 1; y -= 1
    if flag:
        if ball[x] > 0:
            ball[x] -= 1
            ball[y] += 1
            if gray[x]:
                gray[y] = True
    if not flag and x == 0:
        flag = True
        gray[y] = True
        ball[x] -= 1
        ball[y] += 1

if flag:
    ans = 0
    for i in range(n):
        if gray[i] and ball[i] > 0:
            ans += 1
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

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

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

flag = False
for x, y in xy:
    x -= 1; y -= 1
    if flag:
        ball[x] -= 1
        ball[y] += 1
        if gray[x]:
            gray[y] = True
    if not flag and x == 0:
        flag = True
        gray[y] = True
        ball[x] -= 1
        ball[y] += 1

if flag:
    ans = 0
    for i in range(n):
        if gray[i] and ball[i] > 0:
            ans += 1
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    c = [1] * (N+1)
    p = [False] * (N+1)
    p[1] = True

    for i in range(M):
        if p[x[i]] is True:
            p[y[i]] = True
            c[y[i]] += 1
            c[x[i]] -= 1
        
        if c[x[i]] == 0:
            p[x[i]] = False

    print([i for i in p if i is True].count(True))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ans = 0
for r,a in zip(red, amount):
  if r > 0 and a > 0:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
r=[False]*n
w=[1]*n
r[0]=True
w[0]=0
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if r[x]:
        r[y]=True
    if w[x]==0:
        r[x]=False
    else:
        w[x]-=1
        w[y]+=1
    # print(r,w)
ans=0
for i in r:
    if i:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
r=[False]*n
w=[1]*n
r[0]=True
w[0]=0
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if r[x]:
        r[y]=True
    else:
        w[y]+=1
    if w[x]==0:
        r[x]=False
    else:
        w[x]-=1
    # print(r,w)
ans=0
for i in r:
    if i:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!s = input()
n, m = map(int, input().split())
x = []
y = []
for i in range(m):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
boxes = [False]*n
boxes[0] = True
boxescnt = [1]*n
for i in range(m):
    if boxes[x[i]-1] == True:
        if boxescnt[x[i]-1] == 1:
            boxes[x[i]-1] = False
        boxes[y[i]-1] = True
        boxescnt[x[i]-1] -= 1
        boxescnt[y[i]-1] += 1
print(sum(boxes))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]
#Bは色　Cは個数
B=[0]*N
C=[1]*N
B[0]=1
for i in range(M):   
  if (B[(A[i][0]-1)]==1)and(C[(A[i][0]-1)]==1):
    B[(A[i][1]-1)]=1
    B[(A[i][0]-1)]=0
    C[(A[i][0]-1)]=0
    C[(A[i][1]-1)]+=1
  elif (B[(A[i][0]-1)]==1)and(C[(A[i][0]-1)]>1):
    B[(A[i][1]-1)]=1
    C[(A[i][0]-1)]-=1
    C[(A[i][1]-1)]+=1
print(sum(B))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
x,y = [],[]
for _ in range(M):
	tx,ty = map(int, input().split())
	x.append(tx)
	y.append(ty)

flg = [0] * (N+1)
flg[1] = 1
cnt = [1] * (N+1)
#フラグが１が経っているところからは、移動することで赤を移せる。
for i in range(M):
	cp,np = x[i],y[i]

	if flg[cp] == 1:
		if cnt[cp] == 1:
			flg[cp] = 0
		cnt[cp] -= 1
		cnt[np] += 1
		flg[np] = 1

print(sum(flg))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
red = {}
ball = {}
ans = 1
for i in range(N):
    red[i+1] = 0
    ball[i+1] = 1
red[1] = 1
for i in range(M):
    x,y = map(int,input().split())
    if red[x]:
        if ball[x] == 1:
            red[x] -= 1
            ball[x] -= 1
            if red[y] == 0:
                red[y] += 1
                ball[y] += 1
            else:
                ball[y] += 1
                ans -= 1
        else:
            if red[y] == 0:
                ball[x] -= 1
                red[y] += 1
                ball[y] += 1
                ans += 1
            else:
                ball[x] -= 1
                ball[y] += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
num = [1] * n
red = [0] * n
red[0] = 1

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

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

Submission status: Wrong Answer

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

red_list = [1]
possibility_list = [1]*(n+1)
for i in range(m):
    x,y = map(int,input().split())
    possibility_list[x] -=1
    possibility_list[y] +=1
    if x in red_list:
        red_list.append(y)

del red_list[0]
red_list = list(set(red_list))

ans = 0

for i in red_list:
    if possibility_list[i] >= 1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = [1 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
B[1] = 1
cnt = 1
for _ in range(M):
    a,b = map(int,input().split())
    if B[a]==1 and A[a]>0:
        A[a] -= 1
        if A[a]==0:
            cnt -= 1
            B[a] = 0
        A[b] += 1
        if B[b]==0:
            B[b] = 1
            cnt += 1
print(cnt)