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

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M = map(int,input().split())
A = [1 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
B[1] = 1
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    if B[a]==1 and A[a]>0:
        A[a] -= 1
        A[b] += 1
        B[b]=1
    G[a].append(b)
cnt = 0
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
if A[1]>0:
    cnt += 1
while que:
    x = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append(y)
            hist[y]=1
            if A[y]>0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M = map(int,input().split())
A = [1 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
B[1] = 1
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    if B[a]==1:
        A[a] -= 1
        A[b] += 1
        B[b]=1
    G[a].append(b)
cnt = 0
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
if A[1]>0:
    cnt += 1
while que:
    x = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append(y)
            hist[y]=1
            if A[y]>0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M = map(int,input().split())
A = [1 for _ in range(N+1)]
B = [1]
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    if a in B:
        A[a] -= 1
        A[b] += 1
        B.append(b)
    G[a].append(b)
cnt = 0
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
if A[1]>0:
    cnt += 1
while que:
    x = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append(y)
            hist[y]=1
            if A[y]>0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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 and l[x-1] > 0:
        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)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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)

Submission status: Wrong Answer

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

for i in range(M):

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

    if x == 1 and y == 2:
        N -= 1

    elif x in action_x and y in action_y:
        N -= 1

    action_x.append(x)
    action_y.append(y)
print(N)

Submission status: Wrong Answer

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

for i in range(M):
    if action[i][0] == 1 and action[i][1] == 2:
        N -= 1

    elif i != 1:
        if action[i-1][0] == action[i][0] and action[i-1][1] == action[i][1]:
            N -= 1

print(N)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

print(len(c))

Submission status: Wrong Answer

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

#赤フラグ 玉の個数
arr = [1 for _ in range(n)]
arr1 = [False for _ in range(n)]
arr1[0]=True
ch1 = True

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

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

Submission status: Wrong Answer

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

#赤フラグ 玉の個数
arr = [1 for _ in range(n)]
arr1 = [False for _ in range(n)]
arr1[0]=True
ch1 = True

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

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

Submission status: Wrong Answer

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

#赤フラグ 玉の個数
arr = [[0,1] for _ in range(n)]
arr[0][0]=1
ch1 = True

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

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

Submission status: Wrong Answer

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

#赤フラグ 玉の個数
arr = [[0,1] for _ in range(n)]

ch1 = True

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

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

Submission status: Wrong Answer

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

#赤フラグ 玉の個数
arr = [[0,1] for _ in range(n)]

ch1 = True

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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 cnt[x-1] == 0:
        r[x-1] = 0
        
    if r[x-1] == 1:
        r[y-1] = 1
        
print(sum(r))

Submission status: Wrong Answer

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

cnt = [1] * n
f = [1] + [0] * (n-1)
r = 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 == r:
        r = y
        f[r-1] = 1
    
print(sum(f))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
# 赤が入ってる可能性が0になる場合（すべての球を取り出した場合）があることに注意
n, m = map(int, input().split())
balls = [1 for _ in range(n)]
reddable = [False for _ in range(n)]
reddable[0] = True
for _ in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    if reddable[x] == True:
        reddable[y] = True
        balls[x] -= 1
        balls[y] += 1
    if balls[x] == 0:
        reddable[x] = False

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

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


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

print(box_r.count(1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ans=0
a=[['r'] if i==0 else ['w']for i in range(n)]

for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if  'r' in a[x]:
        a[x].remove('r')
        a[y].append('r')
        ans+=1
        #print(a)
    else:
        a[x].remove('w')
        a[y].append('w')
#print(a)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ans=0
a=[['r'] if i==0 else ['w']for i in range(n)]

for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if  'r' in a[x]:
        a[x].remove('r')
        a[y].append('r')
        ans+=1
        print(a)
    else:
        a[x].remove('w')
        a[y].append('w')
#print(a)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ans=0
t=1
for i in range(m):
    x,y=map(int,input().split())
    if x==t:
        t=y
        ans+=1
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
z = []
box = [0] + [1 for _ in range(n)]
ans = 1
red1 = True
for i in range(m):
    x,y=map(str,input().split())
    box[int(x)] -= 1
    box[int(y)] += 1
    if red1 == False and x in z:
        z += y
    if x == '1' and red1:
        red1 = False
        z += y
    if box[int(x)] == 0 and x in z:
        z.remove(x)
ans = max(ans,len(set(z)))
print(ans)

Submission status: Wrong Answer

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

print(sum(a))

Submission status: Wrong Answer

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

red_list = [1]
ball_num = [1] * n

for i in range(m):
    x, y = map(int, input().split())
    if x in red_list:
        if y not in red_list:
            red_list.append(y)
        ball_num[x-1] -= 1
        ball_num[y-1] += 1
        if ball_num[x-1] == 0:
            red_list = [i for i in red_list if i != x]

print(len(red_list))
print(red_list)

Submission status: Wrong Answer

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

red_list = [1]
ball_num = [1] * n

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

print(len(red_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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()

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = {1}
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        n1_pass = n1_pass - {x}
    if (x in n1_pass):
        n1_pass.add(y)
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = {1}
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        n1_pass = n1_pass - {x}
    if (x in n1_pass):
        n1_pass.add(y)
print(len(n1_pass))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = {1}
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        n1_pass = n1_pass - {x}
    if x == 1 and not flag:
        n1_pass.add(y)
        flag = True
    if flag and (x in n1_pass):
        n1_pass.add(y)
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = {1}
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 box[x] == 0:
        n1_pass = n1_pass - {x}
    
    if x == 1 and not flag:
        n1_pass.add(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.add(y)
        n1_now = y
    
    
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = {1}
n1_now = 0
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    if box[x] == 0:
        n1_pass = n1_pass - {x}
    
    box[x] -= 1
    box[y] += 1
    
    if x == 1 and not flag:
        n1_pass.add(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.add(y)
        n1_now = y
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = set()
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 box[x] == 0:
        n1_pass = n1_pass - {x}
    if x == 1 and not flag:
        n1_pass.add(y)
        n1_now = y
        flag = True
    if flag and x in n1_pass:
        n1_pass.add(y)
        n1_now = y
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = set()
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 box[x] == 0:
        n1_pass = n1_pass - {x}
    if x == 1 and not flag:
        n1_pass.add(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.add(y)
        n1_now = y
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
box = [1]*(N+1)
flag = False
n1_pass = set()
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 == 0:
        n1_pass.remove(x)
    if x == 1 and not flag:
        n1_pass.add(y)
        n1_now = y
        flag = True
    if flag and x == n1_now:
        n1_pass.add(y)
        n1_now = y
ans = 0
for i in n1_pass:
    if box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

for i in range(m):
    x,y = map(int, input().split())
    k = len(red)
    for j in range(k):
        if x==red[j]:
            red.append(y)
            if ball[x-1]==1:
                red.pop(j)
        else:
            continue
    ball[x-1]-=1
    ball[y-1]+=1
red = set(red)
print(len(red))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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


def main():
    N, M = map(int, input().split())
    A = [[0.0, 1.0] for _ in range(N)]
    A[0] = [1.0, 0.0]
    for q in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        s = sum(A[x])
        pa = A[x][0] / s
        pb = A[x][1] / s
        A[y][0] += pa
        A[y][1] += pb
        A[x][0] -= pa
        A[x][1] -= pb
    ans = 0
    for a in A:
        if a[0] != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
array = [1] * N
red = 0
cnt = 0

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

null = array.count(0)
ans = min(cnt, N - null)

print(ans)

Submission status: Wrong Answer

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

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

null = array.count(1)
print(N - null)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
array = [0] * N
red = 0

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

null = array.count(0)
print(N - null)

Submission status: Wrong Answer

Solution code:
_,*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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
li = [0]+[1]*N
m = []
ans = 0
now = 1
for i in range(M):
    x,y = map(int,input().split())
    li[x] -= 1
    li[y] += 1
    if now==x:
        now = y
    if li[y]>1 and now==y or i==M-1 and now==y:
        m.append(y)
m = list(set(m))
m.sort()
for j in m:
    if li[j]!=0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#AGC2 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
cnt = [1]*n
check = [True if i == 0 else False for i in range(n)]
for _ in range(m):
    x,y = LI()
    cnt[x-1] -= 1
    cnt[y-1] += 1
    if check[x-1] == True:
        check[y-1] = True
    elif check[x-1] == False:
        check[y-1] = False
ans = 0
for i in range(n):
    if cnt[i] > 0 and check[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

R=[0 if i!=0 else 1 for i in range(N)]
W=[0 if i==0 else 1 for i in range(N)]
X=[0 if i==0 else 0 for i in range(N)]
#print(R)
#print(W)
#print(X)
k=1
for i in range(M):
  if R[xy[i][0]-1]>0:
    if R[xy[i][0]-1]+W[xy[i][0]-1]>1:
      W[xy[i][0]-1]-=1
      R[xy[i][1]-1]=1
    else:
      R[xy[i][0]-1]-=1
      R[xy[i][1]-1]=1
  else:
      W[xy[i][0]-1]-=1
      W[xy[i][1]-1]+=1
#print(R)
#print(W)

ans=0
for i in range(N):
  if R[i]>0 and R[i]+W[i]>0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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