ZhenlongDai/ACPR huggingface dataset:
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
6 4
1 2
2 3
4 0
1 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
w=[1]*n
p=[0]*n
p[0]=1
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if p[x]:
        p[y]=1
    w[x]-=1
    w[y]+=1
    if w[x]==0:
        p[x]=0
print(sum(p))

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    red = [0] * N
    red[0] = 1
    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if red[x] == 1:
            red[x] -= 1
            red[y] += 1
            cnt[y] += 1

    ans = 0
    for i in cnt:
        if i > 0:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
5 3
2 2
2 3
2 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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()

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[]
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if x in ans: 
    ans.append(y)
    if cnt[x]==0:
      ans.pop(ans.index(x))
print(len(ans))

Failing test case input:
6 4
1 2
2 3
4 1
1 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[False]*(N+1)
ans[1]=True
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if ans[x] and not ans[y]: 
    ans[y]=True
  if ans[x] and cnt[x]==0:
    ans[x]=False
print(sum(ans))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
x = []
y = []
red = [0]
mas = [1 for i in range(N)]

for i in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    mas[x] -= 1
    mas[y] += 1
    if x in red:
        if x not in red:
            red.append(y)
        if mas[x] == 0:
            red.remove(x)

print(len(red))

        
    


Failing test case input:
6 2
1 4
3 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
x = []
y = []
red = [0 for i in range(N)]
mas = [1 for i in range(N)]
red[0] = 1

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

print(sum(red))

Problem: p04034
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,m=map(int,input().split())
a=[1]*(n+1)
b=[0]*(n+1)
b[1]=1
for _ in range(m):
  x,y=map(int,input().split())
  a[x]-=1
  a[y]+=1
  if b[x]:b[y]=1
ans=0
for i,j in zip(a,b):
  ans+=(i!=0)*j
print(ans)

Failing test case input:
4 4
1 2
2 3
4 0
1 0

Expected output:
2


Actual output:
4


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

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline

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

Failing test case input:
14 2
1 6
1 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline

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

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int,input().split())
f = [True] * n
num = [1] * n

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

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

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

    f[y] = True

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

print(cnt)

Failing test case input:
6 4
1 2
2 3
4 0
1 0

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n, m = map(int,input().split())
f = [False] * n
f[0] = True
num = [1] * n

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

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

    if f[x]:
        f[y] = f[x]

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

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

print(cnt)
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)



Failing test case input:
6 4
1 3
2 0
4 1
1 0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
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

    ball[y]+=1
    ball[x]-=1
    if ball[x]==0:
        check[x]=False

print(check.count(True))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
7 4
1 2
2 0
4 1
1 0

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
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:
            box[x-1][1] = 0
            ans -= 1


print(ans)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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:
    
    if a:
        ans += 1

print(ans)


Failing test case input:
6 2
1 2
4 6

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
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:
    
    if a > 0:
        ans += 1

print(ans)
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)




Failing test case input:
4 4
1 2
2 3
4 0
0 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
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:
            box[x-1][1] = 0
            ans -= 1


print(ans)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
  t = input().split(" ")
  N, M = int(t[0]), int(t[1])
  x = [1]
  for i in range(M):
    t = input().split(" ")
    fr, to = int(t[0]), int(t[1])
    if fr in x:
      x.append(to)
  print(len(x))
  
main()

Failing test case input:
6 4
1 2
2 3
4 1
1 0

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
def main():
  t = input().split(" ")
  N, M = int(t[0]), int(t[1])
  x = set([0])
  n = [1]*N
  for i in range(M):
    t = input().split(" ")
    fr, to = int(t[0])-1, int(t[1])-1
    if fr in x:
      x.add(to)
    n[fr] -= 1
    n[to] += 1
    if (fr in x) and n[fr] == 0:
        x.remove(fr)
  print(len(x))

main()

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())

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


Failing test case input:
6 2
1 1
4 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))
Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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)


Failing test case input:
4 4
1 2
2 3
4 1
3 0

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
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
    ball[x] -= 1
    ball[y] += 1
    if gray[x]:
        gray[y] = True
    if not ball[x]:
        gray[x] = False

print(sum(gray))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
4 4
1 2
2 3
4 1
1 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
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
    if amount[x-1] == 0:
      red[x-1] = 0
ans = 0
for r,a in zip(red, amount):
  if r > 0 and a > 0:
    ans += 1



print(ans)

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
xy = [list(map(int,input().split())) for _ in range(m)]

cnt = [1] * n
f = [0] * n
b = 1
for x, y in xy:
    cnt[x-1] -= 1
    cnt[y-1] += 1
    
    if cnt[x-1] == 0:
        f[x-1] = 0
        
    if x == b:
        b = y
        f[b-1] = 1

print(sum(f))

Failing test case input:
4 4
2 2
2 3
4 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
x=[0]*n
x[0]=1
y=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  x[b-1]=x[a-1]
  y[a-1]-=1
  y[b-1]+=1
  if y[a-1]==0:x[a-1]=0
print(sum(x))

Failing test case input:
3 2
1 0
2 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
x=[0]*n
x[0]=1
y=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if x[a-1]==1:x[b-1]=1
  y[a-1]-=1
  y[b-1]+=1
  if y[a-1]==0:x[a-1]=0
print(sum(x))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
3 2
2 0
2 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())


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

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

    if A[x][1] == 0:
        A[x][0] = 0

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

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

Failing test case input:
4 4
1 1
0 3
4 0
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

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

ans = 0
for i in range(N):
    if b[i] == True and l[i] > 0:
        ans += 1
print(ans)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
4 4
1 1
0 3
4 0
3 4

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
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 v[a-1]:
        v[b-1]=1
        fi+=1
    if ans[a-1]==0:
        v[a-1]=0
        fi-=1

print(sum(v))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
flg=[0]*(N+1)
flg[1]=1
flg2=[1]*(N+1)
for _ in range(M):
    xy=list(map(int,input().split()))
    flg[xy[1]]=flg[xy[0]]
    flg2[xy[1]]+=1
    flg2[xy[0]]-=1
    if flg2[xy[0]] == 0:
        flg[xy[0]]=0
print(sum(flg))

Failing test case input:
4 4
1 1
0 3
4 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
flg=[0]*(N+1)
flg[1]=1
flg2=[1]*(N+1)
for _ in range(M):
    xy=list(map(int,input().split()))
    if flg[xy[0]]==1:
        flg[xy[1]]=1
    flg2[xy[1]]+=1
    flg2[xy[0]]-=1
    if flg2[xy[0]]==0:
        flg[xy[0]]=0
print(sum(map(lambda x:x>0,flg)))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline

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

Failing test case input:
4 4
1 2
2 3
4 1
3 4

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline

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

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
x = []
y = []

for i in range(M):
    u,v = map(int,input().split())
    x.append(u-1)
    y.append(v-1)
    
red = [0]
mas = [1 for i in range(N)]

for j in range(M):
    mas[x[j]] -= 1
    mas[y[j]] += 1
    if x[j] in red:
        if x[j] not in red:
            red.append(y[j])
        if mas[x[j]] == 0:
            red.remove(x[j])

print(len(red))


Failing test case input:
7 4
1 2
2 0
3 1
1 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
x = []
y = []
red = [0 for i in range(N)]
mas = [1 for i in range(N)]
red[0] = 1

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

print(sum(red))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
stack = [1]*n
p = [False]*n
p[0] = True

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

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


Failing test case input:
3 3
1 2
2 3
2 3

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
stack = [1]*n
p = [False]*n
p[0] = True

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

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

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
7 4
1 2
1 3
7 0
0 0

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
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]:
        red[y] = 1
    num[x] -= 1
    num[y] += 1
    if num[x] == 0:
        red[x] = 0

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

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
x=[0]*n
x[0]=1
for i in range(m):
  a,b=map(int,input().split())
  if x[a-1]==1:x[b-1]=1
print(sum(x))

Failing test case input:
3 2
1 3
3 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
x=[0]*n
x[0]=1
y=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if x[a-1]==1:x[b-1]=1
  y[a-1]-=1
  y[b-1]+=1
  if y[a-1]==0:x[a-1]=0
print(sum(x))

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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))

Failing test case input:
4 4
1 4
2 3
4 1
3 1

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import copy
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
    if Ball[x]:
        Ball[y] = True 
    if BallNum[x] == 0:
        Ball[x] = False
print(sum(Ball))
Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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
        if kosu[x]==1:
            can[x]=0
        kosu[x]-=1
        kosu[y]+=1
print(can.count(1))


Failing test case input:
4 4
1 1
2 3
4 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
  b[y]+=1
  red[y]=red[x]
  
  b[x]-=1
  if b[x]==0:
    red[x]=False
    
print(red.count(True))

Failing test case input:
4 4
1 1
2 3
4 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))
  
  

Failing test case input:
4 4
1 1
2 3
1 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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] -= 1
  balls[y] += 1
  if red[x]:
    red[y] = 1
  if balls[x]==0:
    red[x] = 0
print(sum(red))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)
      

Failing test case input:
7 4
1 2
2 0
4 1
1 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
        A[b] += 1
        if B[b]==0:
            B[b]=1
            cnt += 1
print(cnt)

Failing test case input:
4 4
1 1
0 3
4 0
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
A = [1 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
B[1] = 1
for _ in range(M):
    a,b = map(int,input().split())
    A[b] += 1
    if B[a]==1 and B[b]==0:
        B[b] = 1
    A[a] -= 1
    if B[a]==1 and A[a]==0:
        B[a] = 0
print(sum(B))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
  red[y]=red[x]
  
  b[x]-=1
  if b[x]==0:
    red[x]=False
    
print(red.count(True))


Failing test case input:
12 2
1 3
2 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
aru=1
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 aru==x:
      aru=y
      if a[x-1]!=0:
        ans.add(x)
      elif a[x-1]==0 and x in ans:ans.remove(x)
print(len(ans))

Failing test case input:
15 2
0 6
1 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
aru=1
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 aru==x:
      aru=y
      if a[x-1]!=0:
        ans.add(x)
      elif x in ans:ans.remove(x)
print(len(ans))

Failing test case input:
6 2
1 4
5 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
data=[1]*n
res=[1]+[0]*(n-1)
for i in range(m):
  x,y=map(int,input().split())
  data[x-1]-=1
  data[y-1]+=1
  res[y-1]=res[x-1]
ans=0
for i in range(n):
  if data[i]!=0 and res[i]!=0:
    ans+=1
print(ans)

Failing test case input:
4 4
1 1
2 3
4 1
3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
data=[1]*n
d=[1]+[0]*(n-1)
for i in range(m):
  x,y=map(int,input().split())
  data[x-1]-=1
  data[y-1]+=1
  if d[x-1]==1:
    d[y-1]=1
  if data[x-1]==0:
    d[x-1]=0
print(d.count(1))
Problem: p04034
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
import collections
import fractions
import itertools
import functools
import  operator

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

if __name__ == "__main__":
    solve()

Failing test case input:
12 2
1 4
2 3

Expected output:
1


Actual output:
11


Fixed submission (verdict: Accepted):
import math
import collections
import fractions
import itertools
import functools
import  operator

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

if __name__ == "__main__":
    solve()

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


INF = float('inf')


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


N, M = inpl()
move = [inpl() for _ in range(M)]

ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]

for i in range(M):
    x, y = move[i]
    box[x - 1] -= 1
    box[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if box[x - 1] == 0:
            ans[x - 1] = 0
    


print(sum(ans), ans)

Failing test case input:
3 2
2 0
3 3

Expected output:
1


Actual output:
1 [1, 0, 0]


Fixed submission (verdict: Accepted):


INF = float('inf')


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


N, M = inpl()
move = [inpl() for _ in range(M)]

ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]

for i in range(M):
    x, y = move[i]
    box[x - 1] -= 1
    box[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if box[x - 1] == 0:
            ans[x - 1] = 0
    


print(sum(ans))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
	print(li)
	if x in se:
		se.add(y)
		if li[x]==0:
			se.remove(x)
print(len(se))

Failing test case input:
12 2
1 0
2 6

Expected output:
1


Actual output:
[2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[2, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1]
1


Fixed submission (verdict: Accepted):
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))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
num = [1 for c in range(n)]
red = [False for d in range(n)]
red[0] = True
counter = 0
for i in range(m):
    x,y = map(int,input().split())
    red[y-1] = True
    num[x-1] = num[x-1] - 1
    num[y-1] = num[y-1] + 1
for j in range(n):
    if (red[j] == True)&(num[j]>0):
        counter += 1
print(counter)

Failing test case input:
3 2
2 -1
3 3

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
num = [1 for c in range(n)]
red = [False for d in range(n)]
red[0] = True
counter = 0
for i in range(m):
    x,y = map(int,input().split())
    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
for j in range(n):
    if (red[j] == True)&(num[j]>0):
        counter += 1
print(counter)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = []
n1_now = 0
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if x == 1 and not flag:
        n1_pass.append(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.append(y)
ans = 0
for i in set(n1_pass):
    if box[i] > 0:
        ans += 1
print(ans)

Failing test case input:
14 2
0 5
2 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = []
n1_now = 0
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if x == 1 and not flag:
        n1_pass.append(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.append(y)
        n1_now = y
ans = 0
for i in set(n1_pass):
    if box[i] > 0:
        ans += 1
print(ans)

Failing test case input:
6 2
0 3
4 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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)
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int, input().split())
n = [1]*a
r = [0]*a
r[1] = 1

for i in range(b):
    ta,tb = map(int, input().split())
    ta-=1
    tb-=1
    if r[ta] == 1:
        r[tb] = 1
    n[ta] -=1
    n[tb] -=1
    if n[ta] ==0:
        r[ta] = 0
print(sum(r)) 


Failing test case input:
6 2
1 4
4 6

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
a,b = map(int, input().split())
n = [1]*a
r = [0]*a
r[0] = 1

for i in range(b):
    ta,tb = map(int, input().split())
    ta-=1
    tb-=1
    if r[ta] == 1:
        r[tb] = 1
    n[ta] -=1
    n[tb] +=1
    if n[ta] ==0:
        r[ta] = 0
print(sum(r))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
6 4
1 3
2 0
4 1
1 0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
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 = [False] * (n)
ball[0] = True
for i in range(m):
    x, y = xy[i]
    ans[y-1] += 1
    ans[x-1] -= 1
    if ball[x-1]:
      ball[y-1] = True
    if ans[x-1] == 0:
      ball[x-1] = False
      
cnt = 0
for i in ball:
  if i:
    cnt += 1

print(cnt)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
x = []
y = []

for i in range(M):
    u,v = map(int,input().split())
    x.append(u-1)
    y.append(v-1)
    
red = [0]
mas = [1 for i in range(N)]

for j in range(M):
    if x[j] == set(red):
        mas[y[j]] += 1
        mas[x[j]] -= 1
        red.append(y[j])
        if mas[x[j]] == 0:
            red.remove(x[j])

print(len(red))

Failing test case input:
6 2
1 2
2 6

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
x = []
y = []
red = [0 for i in range(N)]
mas = [1 for i in range(N)]
red[0] = 1

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

print(sum(red))

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
dp=[0]*(1+n)
dp[1]=1
for i in range(m):
    x,y=map(int,input().split())
    dp[y]=dp[x]
print(sum(dp))


Failing test case input:
3 2
1 0
2 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
dp=[0]*(1+n)
dp[1]=1
b=[1]*(1+n)
for i in range(m):
    x,y=map(int,input().split())
    dp[y]=max(dp[x],dp[y])
    b[y]+=1
    b[x]-=1
    if b[x]==0:
        dp[x]=0
print(sum(dp))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
x = []
y = []

for i in range(M):
    u,v = map(int,input().split())
    x.append(u-1)
    y.append(v-1)
    
red = [0]
mas = [1 for i in range(N)]

for j in range(M):
    mas[x[j]] -= 1
    mas[y[j]] += 1
    if x[j] in red and x[j] not in red:
        red.append(y[j])
        if mas[x[j]] == 0:
            red.remove(x[j])

print(len(red))

        

Failing test case input:
7 4
1 2
2 0
3 1
1 0

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
x = []
y = []
red = [0 for i in range(N)]
mas = [1 for i in range(N)]
red[0] = 1

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

print(sum(red))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
_,*B=open(0);W=[1]*7**6;R=[0,1]+[0]*7**6
for b in B:x,y=map(int,b.split());W[x]-=1;W[y]+=1;R[y]=R[x]|R[y];R[x]=R[x]and W[x]
print(sum(R))

Failing test case input:
3 2
1 3
3 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
_,*B=open(0);W=[1]*7**6;R=[0,1]+[0]*7**6
for b in B:x,y=map(int,b.split());W[x]-=1;W[y]+=1;R[y]|=R[x];R[x]&=W[x]>0
print(sum(R))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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))



Failing test case input:
5 3
1 2
2 3
2 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):



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)):
    if x[i] in ball_set:
        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))

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
aru=1
a=[1]*n
ans=set()
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 aru==x:
      aru=y
      if a[x-1]!=0:
        ans.add(x)
print(len(ans))

Failing test case input:
6 2
1 4
2 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))
Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int,input().split())
f = [False] * n
f[0] = True
num = [1] * n

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

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

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

    f[y] = True

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

print(cnt)

Failing test case input:
3 2
2 -1
2 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int,input().split())
f = [False] * n
f[0] = True
num = [1] * n

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

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

    if f[x]:
        f[y] = f[x]

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

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

print(cnt)

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
xy = [list(map(int,input().split())) for _ in range(m)]

cnt = [1] * n
f = [0] * n
b = 1
for x, y in xy:
    cnt[x-1] -= 1
    cnt[y-1] += 1
    if x == b:
        b = y
        f[b-1] = 1

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

print(ans)

Failing test case input:
6 0
1 4
1 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p04034
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[1]
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if x in ans: 
    ans.append(y)
    if cnt[x]==0:
      ans.pop(ans.index(x))
print(len(ans))

Failing test case input:
5 3
1 2
2 3
2 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[False]*(N+1)
ans[1]=True
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if ans[x] and not ans[y]: 
    ans[y]=True
  if ans[x] and cnt[x]==0:
    ans[x]=False
print(sum(ans))
Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = []
n1_now = 0
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if x == 1 and not flag:
        n1_pass.append(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.append(y)
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Failing test case input:
3 0
0 2
2 3
2 3

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p04034
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

ans = 0
for i in range(N):
    if b[i] == True and l[i] > 0:
        ans += 1
print(ans)

Failing test case input:
6 4
1 2
2 3
4 0
1 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):

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

ans = 0
for i in range(N):
    if b[i] == True and l[i] > 0:
        ans += 1
print(ans)

Problem: p04034
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict
n, m = map(int, input().split())
r = set()
r.add(1)
d = defaultdict(int)
for i in range(m):
  x, y = map(int, input().split())
  d[x] -= 1
  d[y] += 1
  if x in r:
    r.add(y)
ans = len(list(r))
for e in d:
  if d[e] == -1 and e in r:
    ans -= 1
print(ans)

Failing test case input:
5 3
1 2
2 3
1 3

Expected output:
2


Actual output:
3


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