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())
red = [0]
num = [1] * n
first = 0
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if x in red:
        if first == 0:
            red = [y]
            first += 1
            num[0] = 0
            num[y] += 1
        else:
            if num[x] > 0:
                red.append(y)
                num[x] -= 1
                num[y] += 1
    if x not in red:
        if num[x] > 0:
            num[y] += 1
            num[x] -= 1
ans = 0        
for rr in list(set(red)):
    if num[rr] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N, M = [int(x) for x in stdin.readline().rstrip().split()]
XY = []
for i in range(M):
  x, y = stdin.readline().rstrip().split()
  XY.append([int(x), int(y)])
balls = [1 for i in range(N)]
for x, y in XY:
  balls[x-1] -= 1
  balls[y-1] += 1
counter_balls = Counter(balls)
if 0 in counter_balls:
  print(N-counter_balls[0])
else:
  print(N-1)

Submission status: Wrong Answer

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

B = [1]*N
R=[False]*N

R[True]=1

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

print(sum(R))

Submission status: Wrong Answer

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


def main():
    n, m = map(int, input().split())
    white = [1 for _ in range(n)]
    white[0] = 0
    red = [0 for _ in range(n)]
    red[0] = 1
    ans = [0 for _ in range(n)]
    ans[0] = 1

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

        if white[xi] == 0:
            red[xi] -= 1
            red[yi] += 1
            ans[xi] = 0
            ans[yi] = 1
        else:
            white[xi] -= 1
            white[yi] += 1

            if ans[xi] == 1:
                ans[yi] = 1

    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AGC002B - Box and Ball
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(M))
    R = [0] * (N + 1)  # red ball may be in box i
    R[1] = 1
    C = [1] * (N + 1)  # number of balls in box i (count)
    for x, y in X:
        R[y] = 1 if R[x] or R[y] else 0
        C[x] -= 1
        C[y] += 1
        R[x] = 0 if R[x] == 0 else R[x]
    ans = sum(R[1:])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# AGC002B - Box and Ball
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(M))
    A = [0] * (N + 1)  # red ball may be in box i
    A[1] = 1
    B = [1] * (N + 1)  # number of balls in box i
    for x, y in X:
        
        A[y] = 1 if A[x] or A[y] else 0
        B[x] -= 1
        B[y] += 1
    # red ball moved to a box once and a ball there after the operation -> +1
    ans = sum(i > 0 and j > 0 for i, j in zip(A[1:], B[1:]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# AGC002B - Box and Ball
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(M))
    A = [0] * (N + 1)  # red ball may be in box i
    A[1] = 1
    B = [1] * (N + 1)  # number of balls in box i
    for x, y in X:
        A[y] = 1 if A[x] else 0
        B[x] -= 1
        B[y] += 1
    # red ball moved to a box once and a ball there after the operation -> +1
    ans = sum(i > 0 and j > 0 for i, j in zip(A[1:], B[1:]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,*l=map(int,open(0).read().split());a=[0,1]+[0]*n;b=[1]*-~n
for i,j in zip(l[1::2],l[2::2]):a[j]|=a[i];b[i]-=1;b[j]+=1;a[i]&=b[i]
print(sum(a))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
balls=[1 for i in range(n)]
pro=[False for i in range(n)]
pro[0]=True

for inp in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    balls[a]-=1
    balls[b]+=1
    if pro[a]:
        pro[b]=True
    
for i in range(n):
    if balls[i]==0:
        pro[i]=False

#print(pro)
print(pro.count(True))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
xy = []
for i in range(0,m):
    xy.append(list(map(int,input().split())))
ab = [[0,1] for j in range(n)]
ab[0] = [1,0]
for i in range(0,m):
    before = xy[i][0]-1
    after = xy[i][1]-1

    ab_a = ab[before][0]/(ab[before][0]+ab[before][1])
    ab_b = ab[before][1]/(ab[before][0]+ab[before][1])
    
    ab[before][0] -= ab_a
    ab[before][1] -= ab_b
    ab[after][0] += ab_a
    ab[after][1] += ab_b
count = 0
for i in range(0,n):
    if ab[i][0]>0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
xy = []
for i in range(0,m):
    xy.append(list(map(int,input().split())))
ab = [[0,1] for j in range(n)]
ab[0] = [1,0]
for i in range(0,m):
    before = xy[i][0]-1
    after = xy[i][1]-1

    ab_a = ab[before][0]/(ab[before][0]+ab[before][1])
    ab_b = ab[before][1]/(ab[before][0]+ab[before][1])
    
    ab[before][0] -= ab_a
    ab[before][1] -= ab_b
    ab[after][0] += ab_a
    ab[after][1] += ab_b
count = 0
for i in range(0,n):
    if ab[i][0]>0.0000001:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
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(map(lambda x:x>0,flg)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
box_1 = [1 for j in range(N)]
box_2 = [0 for k in range(N)]
box_2[0] = 1
for i in range(M):
  x,y = map(int,input().split())
  box_1[x-1]-=1
  box_1[y-1]+=1
  box_2[y-1]=1
counter = 0
for l in range(N):
  if(box_1[l]>=1)and(box_2[l]==1):
    counter+=1
print(counter)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
B = [1]*N
R = [1]+[0]*(N-1)
for i in range(M):
    x,y = map(int,input().split(" "))
    x -= 1
    y -= 1
    B[x] -= 1
    B[y] += 1
    R[y] = R[x]
    R[x] = B[x] and R[x]

print(sum(R))

Submission status: Wrong Answer

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

red = set([1])
n_ball = [1]*(N+1)

for x,y in XY:
  n_ball[x] -= 1
  n_ball[y] += 1
  if x in red:
    red.add(y)
    if n_ball[x]==0:
      red.remove(x)
  print(red)
  print(n_ball)
print(len(red))

Submission status: Wrong Answer

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

red = set([1])
n_ball = [1]*(N+1)

for x,y in XY:
  if x in red:
    red.add(y)
    n_ball[x] -= 1
    n_ball[y] += 1
    if n_ball[x]==0:
      red.remove(x)
print(len(red))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

p.remove(1)
ps = list(set(p))
ans = 0
for i in ps:
    if stack[i-1] != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

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

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
W=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
BOX=[[1,1]]
BOX.extend([[1,0] for _ in range(N)])
for i in range(M):
    BOX[W[i][0]][0]=BOX[W[i][0]][0]-1
    BOX[W[i][1]][0]=BOX[W[i][1]][0]+1
    if(BOX[W[i][0]][1]==1):
        BOX[W[i][1]][1]=1
        if(BOX[W[i][0]][0]==1):
            BOX[W[i][0]][1]=0
print(sum(list(map(lambda x:x[:][1],BOX))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


def update(fr, to):
    if box[fr] == 1:
        red[to] = red[fr]
        box[fr] -= 1
        red[fr] = False
        box[to] += 1
    else:
        red[to] = red[fr]
        box[fr] -= 1
        box[to] += 1


for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    update(a, b)

ans = sum(red)
print(ans)

Submission status: Wrong Answer

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

A = [1 for i in range(N+1)]

red = [1]
ans = 1
for i in range(M) :
    A[L[i][0]] -= 1
    A[L[i][1]] += 1
    if L[i][0] in red :
        red.append(L[i][1])
        if A[L[i][0]] == 0 :
            red.remove(L[i][0])

ans = len(list(set(red)))
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
c = []
for i in range(m):#h:高さ
    c.append([int(m) for m in input().split()])
ball = []
for i in range(n + 1):
    if i == 1:
        ball.append([1, 0, 1])
    else:
        ball.append([0, 1, 1])
for i in range(m):
    if ball[c[i][0]][0] == 0:
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][1] += 1
        ball[c[i][0]][1] -= 1
    elif ball[c[i][0]][1] == 0:
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][0] = 1
        ball[c[i][0]][0] -= 1
    else:
        if ball[c[i][0]][2] == 1:
            ball[c[i][0]][0] = 0
            ball[c[i][0]][1] = 0
        else:
            ball[c[i][0]][1] -= 1
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][0] = 1
        
ans = 0
for i in range(n + 1):
    if ball[i][0] >= 1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
c = []
for i in range(m):#h:高さ
    c.append([int(m) for m in input().split()])
ball = []
for i in range(n + 1):
    if i == 1:
        ball.append([1, 0, 1])
    else:
        ball.append([0, 1, 1])
for i in range(m):
    if ball[c[i][0]][0] == 0:
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][1] += 1
        ball[c[i][0]][1] -= 1
    elif ball[c[i][0]][1] == 0:
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][0] = 1
        ball[c[i][0]][0] -= 1
    else:
        if ball[c[i][0]][2] == 1:
            ball[c[i][0]][0] = 0
            ball[c[i][0]][1] = 0
        ball[c[i][0]][2] -= 1
        ball[c[i][1]][2] += 1
        ball[c[i][1]][0] = 1
ans = 0
for i in range(n + 1):
    if ball[i][0] >= 1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
f = [False for _ in range(n)]
c = [1 for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().split())
  f[y - 1] = f[y - 1] or f[x - 1]
  c[y - 1] += 1
  c[x - 1] -= 1
ans = 0
for i in range(n):
  if f[i] and c[i] > 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
f = [False for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().split())
  f[y - 1] = f[y - 1] or f[x - 1]
ans = f.count(True)
print(ans if ans <= 1 else ans - 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
f = [False for _ in range(n)]
f[0] = True
for i in range(m):
  x, y = map(int,input().split())
  f[y - 1] = f[y - 1] or f[x - 1]
print(f.count(True))

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())  

class Box:
      def __init__(self):
         self.ball = 1
         self.pos = False
box = [] 
for i in range(N):
    box.append(Box())
box[1].pos = True

for i in range(M):
    x,y = (int(i) for i in input().split())  
    if box[x - 1].pos:
       box[y - 1].pos = True
    box[x - 1].ball -= 1
    box[y - 1].ball += 1
    if box[x - 1].ball == 0:
       box[x - 1].pos = False
cnt = 0;
for i in range(N):
   if box[i].pos:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
lis = [[1,0] for i in range(n)]
lis[0][1] = 1
ans = 1
for i in range(m):
  a,b = map(int,input().split())
  if lis[a-1][1] == 1:
    lis[b-1][1] = 1
  lis[b-1][0] += 1
  lis[a-1][0] -= 1
  if lis[a-1][0] == 0:
    lis[a-1][1] = 0
for i in range(n):
  if lis[i][1] == 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
lis = [[1,0] for i in range(n)]
lis[0][1] = 1
ans = 1
for i in range(m):
  a,b = map(int,input().split())
  if lis[a-1][1] == 1:
    lis[b-1][1] = 1
    ans += 1
  lis[b-1][0] += 1
  lis[a-1][0] -= 1
  if lis[a-1][0] == 0:
    lis[a-1][1] = 0
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split());n,m=i();a=[0]+[1]*n;b=[0,1]+[0]*n
for _ in[0]*m:x,y=i();a[x]-=1;a[y]+=1;b[y]|=b[x];b[x]&=a[x]
print(sum(b))

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]=l[x];c[y]+=1;c[x]-=1;l[x]=c[x]and l[x]
print(sum(c[i]and l[i]for i in range(n+1)))

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]=l[x];c[y]+=1;c[x]-=1;l[x]=c[x]>0
print(sum(c[i]and l[i]for i in range(n+1)))

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]=l[x];c[y]+=1;c[x]-=1
print(sum(c[i]>0and l[i]for i in range(n+1)))

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split());n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n
for _ in[0]*m:x,y=i();l[y]=l[x];c[y]+=1;c[x]-=1
print(sum(c[i]and l[i]for i in range(n+1)))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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)]
# print(ans, box)
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(ans, box)


print(sum(ans), ans)

Submission status: Wrong Answer

Solution code:
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]

n,m = f()
sus = set()
conf = [0]
num = [1 for _ in range(n)]
for _ in range(m):
    x,y = f_()
    if x in conf:
        if num[y]==0:
            conf = [y]
        else:
            conf = []
            sus.add(y)
    elif y in conf:
        conf = []
        sus.add(y)
    elif x in sus:
        sus.add(y)
    num[x] -= 1; num[y] += 1
print(max(len(sus),1))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
#print(N,M)
list1=[[0],[1]]
for i in range(N-1):
    list1.append([0])
#print(list1)
for j in range(M):
    a1,a2=map(int,input().split())
    list1[a2].append(list1[a1][0])
    if list1[a1][0]==1:
        del list1[a1][0]
        for k in range(len(list1[a2])):
            list1[a2][k]=1
    else:
        del list1[a1][0]
#print(list1)
cnt=0
for l in range(len(list1)):
    if 1 in list1[l]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(m)]

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

red[1] = 1
white[1] = 0

for x, y in X:
    if red[x] == 1:
        if white[x] >= 1:
            white[x] -= 1
        else:
            red[x] -= 1

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

    else:
        white[x] -= 1
        white[y] -= 1

print(sum(red))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
c=[0 for i in range(N)]
c[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
    if b[x[i]]!=0:
        c[x[i]]=1
    else:
        c[x[i]]=0
    if t!=0:
        c[y[i]]=1
print(sum(c))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N**2
c=[0 for i in range(N)]
c[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
    if b[x[i]]!=0:
        c[x[i]]=1
    else:
        c[x[i]]=0
    if t!=0:
        c[y[i]]=1
print(sum(c))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N**2
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if a[i]!=0:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if a[i]!=0:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=N*t/(b[x[i]]+1)
    a[y[i]]+=N*t/(b[x[i]]+1)
n=0
for i in range(N):
    if a[i]!=0:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if abs(a[i])>0:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if abs(a[i])>1.0e-12:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-15:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-10:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-30:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-20:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-7:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-6:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=N
for i in range(N):
    if abs(a[i])<1.0e-5:
        n-=1
print(n)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if a[i]!=0:
        n+=1
print(n)

Submission status: Wrong Answer

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

array = []

red_array = [[0, 1, 0] for x in range(100000)]
red_array[0] = [1, 0, 0]

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

    # (取られる側に)赤いボールが存在しない場合
    if red_array[s][0] == 0:
        red_array[s][2] += 1
    else:
        # (取る側に)赤いボールが存在しない場合
        if red_array[e][0] == 0:
            red_array[e][0] += 1
            red_array[s][2] += 1
        # (取る側に)赤いボールが存在する場合
        else:
            red_array[s][2] += 1

    if red_array[s][2] == red_array[s][0] + red_array[s][1]:
        red_array[s][0] = 0

res = 0
for i in red_array:
    if i[0] == 1:
        res += 1
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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:
        red.append(y[j])
        if mas[x[j]] == 0:
            red.remove(x[j])
print(len(red))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
x = []
y = []
count = []
box = [[0] for i in range(N)]
red = 0
res = 0

for i in range(M):
    u,v = map(int,input().split())
    x.append(u-1)
    y.append(v-1)
    
for j in range(M):
    a = x[j]
    b = y[j]
    if a == red:
        count.append(b)
        red = b
    box[b].append(box[a].pop)

for k in range(len(count)):
    if box[count[k]] != []:
        res += 1

print(res)

Submission status: Wrong Answer

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

boxes = [1 for i in range(N + 1)]
reds  = [0 for i in range(N + 1)]
reds[0] = 1
current = 1

for i in range(0, M):

    x, y = map(int, raw_input().strip().split())
    boxes[x] -= 1
    boxes[y] += 1
    if(x == current) :
        current = y
        reds[y] = 1

count = 0
for i in range(1, N+1):
    if reds[i] > 0 and boxes[i] > 0:
        count += 1

print count