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: Accepted

Solution code:
N,M=map(int,input().split())
S={1}
C=[1] * (N+1)
for _ in range(M):
    a,b=map(int,input().split())
    if a in S:
        S.add(b)
        if C[a] == 1:
            S.remove(a)
    C[b] += 1
    C[a] -= 1
print(len(S))

Submission status: Accepted

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

XY= [list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]


red= [False for i in range(N)]
red[0]=True
balls= [1 for i in range(N)]


for x,y in XY:
    if red[x]==True:
        red[y]=True
    balls[x]-=1
    balls[y]+=1
    if balls[x]==0:
        red[x]=False
print(sum(bool(red[i] and balls[i]) for i in range(N)))

Submission status: Accepted

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

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

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

print(len([True for r in red if r > 0]))

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1

box = []
for i in range(N):
    box.append([i,1,0])
box[0][2] = 1

a = [0]
for i in range(M):
    if xn[i] in a:
        if box[xn[i]][1] !=0:
            box[xn[i]][1] -=1
            box[yn[i]][1] +=1
            box[yn[i]][2] =1
            a.append(yn[i])  
        if box[xn[i][1] ==0:
            continue

count = 0
for i in range(N):
    if box[i][1] !=0 and box[i][2] ==1:
        count +=1
        
print(count)

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1

box = []
for i in range(N):
    box.append([i,1,0])
box[0][2] = 1

a = [0]
for i in range(M):
    if xn[i] in a:
        if box[xn[i],1] !=0:
            box[xn[i]][1] -=1
            box[yn[i]][1] +=1
            box[yn[i]][2] =1
            a.append(yn[i])  
        if box[xn[i],1] ==0:
            continue

count = 0
for i in range(N):
    if box[i][1] !=0 and box[i][2] ==1:
        count +=1
        
print(count)

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1

box = []
for i in range(N):
    box.append([i,1,0])
box[0][2] = 1

a = [0]
for i in range(M):
    if xn[i] in a:
        if xn[i][1] !=0:
            box[xn[i]][1] -=1
            box[yn[i]][1] +=1
            box[yn[i]][2] =1
            a.append(yn[i])  
        if xn[i][1] ==0:
            continue

count = 0
for i in range(N):
    if box[i][1] !=0 and box[i][2] ==1:
        count +=1
        
print(count)

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1

box = []
for i in range(M):
    box.append([i,1,0])
box[0][2] = 1


a = [0]
for i in range(M):
    if xn[i] in a:
        box[xn[i]][1] -=1
        box[yn[i]][1] +=1
        box[yn[i]][2] =1
        a.append(yn[i])    

count = 0
for i in range(M):
    if box[i][1] !=0 and box[i][2] ==1:
        count +=1
print(count)

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1

box = []
for i in range(M):
    box.append([i,1])

a = [0]
for i in range(M):
    if xn[i] in a:
        box[i][1] -=1
        box[yn[i]][1] +=1
        a.append(yn[i])
        
count = M
for i in range(M):
    if box[i][0] == 0:
        count -=1
print(count)

Submission status: Runtime Error

Solution code:
#  AtCoder Grand Contest 002 B

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

xn = [0] * M
yn = [0] * M

for i in range(M):
    xn[i],yn[i] = map(int,input().split())

for i in range(M):
    xn[i] -=1
    yn[i] -=1
    
print(xn)
print(yn)

box = []
for i in range(M):
    box.append([i,1])
print(box)

a = [0]
for i in range(M):
    if xn[i] in a:
        box[i][1] -=1
        box[yn[i]][1] +=1
        a.append(yn[i])
        
count = M
for i in range(M):
    if box[i][0] == 0:
        count -=1
print(count)

Submission status: Runtime Error

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

L = []

if flag == False:
    print(1)
    exit()
for i in range(m):
    x,y = L[i][0],L[i][1]
    x,y = x-1,y-1
    if kosuu[x] >=2 and possible[x] == 1:
        possible[y] = 1
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 1:
        possible[x] = 0
        possible[y] = 1
        kosuu[x] = 0
        kosuu[y] +=1
    elif kosuu[x] >=2 and possible[x] == 0:
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 0:
        kosuu[x] = 0
        kosuu[y] +=1
print(sum(possible))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
possible = [0]*n
kosuu = [1]*n
possible[0] = 1
L = []

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

for i in range(idx,m):
    x,y = L[i][0],L[i][1]
    x,y = x-1,y-1
    if kosuu[x] >=2 and possible[x] == 1:
        possible[y] = 1
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 1:
        possible[x] = 0
        possible[y] = 1
        kosuu[x] = 0
        kosuu[y] +=1
    elif kosuu[x] >=2 and possible[x] == 0:
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 0:
        kosuu[x] = 0
        kosuu[y] +=1
        
print(sum(possible))

Submission status: Runtime Error

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

possible = [0]*n
possible[0] = 1
kosuu = [1]*n

for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
        
    if kosuu[a] >= 2 and possible[a] ==1:
        possible[a] = 1 
        possible[b] = 1
        kosuu[a] -=1
        kosuu[b] +=1
    elif kosuu[a] ==1 and possible[a] ==1 : 
        possible[a] = 0
        possible[b] = 1
        kosuu[a] = 0
        kosuu[b] +=1
    if kosuu[a] >= 2 and possible[a] ==0:
        possible[a] = 0
        possible[b] = 0
        kosuu[a] -=1
        kosuu[b] +=1
    elif kosuu[a] ==1 and possible[a] == : 
        possible[a] = 0
        possible[b] = 0
        kosuu[a] = 0
        kosuu[b] +=1
    #print(possible,kosuu)
print(sum(possible))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long ,long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin();
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin();
#define ct(i) cout<< i << "\n";
#define sv(v) sort(v.begin(),v.end());
#define mod 1000000007
#define M 100005
#define endl "\n"

// std::vector<int> ad[100005];

// int vis[100005]={},intime[100005],low[100005],timer=0;
// int flag=0;
// vector<pair<int,int>> ans;

// void dfs(int node, int par){
//     vis[node]=1;
//     intime[node]=low[node]=timer++;
//     for(auto child:ad[node]){
//         if(child==par) continue;
//         if(vis[child]){
//             low[node] = min(low[node],low[child]);
//             if(intime[child]<intime[node]) ans.pb({node,child});
//         }
//         else{
//             dfs(child,node);
//             if(low[child]>intime[node]){
//                 flag=1;
//                 return;
//             }
//             low[node] = min(low[child],low[node]);
//             ans.pb({node,child});
//         }
//     }
// }

void answer(){
    ll n,m,x,y,ans=0;
    cin>>n>>m;
    int a[n+1],b[n+1];
    for(int i=0;i<=n;i++) a[i]=0,b[i]=1;
    a[1]=1;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        if(a[x]==1){
            a[y]=1;
        }
        b[x]--;
        b[y]++;
        if (b[x]==0){
            a[x]=0;
        }
    }
    
    for(int i=1;i<=n;i++){
        ans+=a[i];
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int q;
    //cin>>q; while(q--)
        answer();

    return 0;
}

Submission status: Runtime Error

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(y)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

Submission status: Runtime Error

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]

#赤玉の初回移動までは捨てる
for i in range(M):
    x,y = map(int, input().split())
    if x == 1:
        red_ball_containable_box = set()
        red_ball_containable_box.add(y)
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        start = i + 1
        break
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

for j in range(start,M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        red_ball_containable_box.add(y)
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

Submission status: Runtime Error

Solution code:
R=[0]
L=list()
N=int(input())
for i in range(N):
  k=int(input())
  L.append(k)
  if k==0:
    R.append(len(L))
S=sum(L)
R.append(N)
for i in range(len(R)-1):
  if sum(L[R[i]:R[i+1]])%2==1:
    S=S-1
print(S//2)

Submission status: Runtime Error

Solution code:
R=list()
L=list()
N=int(input())
for i in range(N):
  k=int(input())
  L.append(k)
  if k==0:
    R.append(len(L))
S=sum(L)
for i in range(len(R)-1):
  if sum(L[R[i]-1:R[i+1]])%2==1:
    S=S-1
print(S//2)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
R=list()
R.append(1)
L=[1]*N
for i in range(M):
  a,b=map(int,input().split())
  L[a-1]=L[a-1]-1
  L[b-1]=L[b-1]+1
  if a in R:
    if L[a-1]==0:
      R.remove(a)
    R.append(b)
for j in range(len(R)):
  k=R[j]
  if L[k-1]==0:
    R.remove(k)
R=set(R)
print(len(R))

Submission status: Runtime Error

Solution code:
redBalles = []
currentRedBall = 0

def putBall(i, balles, routes):
    global redBalles
    global currentRedBall
    if i == len(routes):
        redBalles[currentRedBall] = 1
        return None
    _from = routes[i][0]-1
    _to = routes[i][1]-1
    if balles[_from]%2 == 0:
        balles[_from] -= 2
        balles[_to] += 2
        putBall(i+1, balles, routes)
    else:
        if balles[_from] == 1:
            balles[_from] -= 1
            balles[_to] += 1
            currentRedBall = _to
            putBall(i+1, balles, routes)
        else:
            _balles = [b for b in balles]
            _balles[_from] -= 1
            _balles[_to] += 1
            currentRedBall = _to
            putBall(i+1, _balles, routes)
            
            _balles = [b for b in balles]
            _balles[_from] -= 2
            _balles[_to] += 2
            currentRedBall = _from
            putBall(i+1, _balles, routes)

def answer(n, routes):
    global redBalles
    redBalles = [0]*n
    balles = [1] + [2]*(n-1)
    putBall(0, balles, routes)
    return sum(redBalles)

n, m = map(int, input().split())
routes = []
for _ in range(m):
    routes.append(list(map(int, input().split())))
print(answer(n, routes))

Submission status: Runtime Error

Solution code:
def solve():
    N, M = map(int, input().split())
    
    num = []
    red = []
    for i in range(N+1):
        num.append(1)
        red.append(0)
    red[1] = 1
    
    for _ range(M):
        x, y = map(int, input().split())
        if red[x] == 1:
            red[y] = 1
        num[x] -= 1
        num[y] += 1
        if num[x] == 0:
            red[x] = 0
    
    return sum(red)

print(solve())

Submission status: Runtime Error

Solution code:
    import sys, re, os
    from collections import deque, defaultdict, Counter
    from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
    from itertools import permutations, combinations, product, accumulate
    from operator import itemgetter, mul
    from copy import deepcopy
    from string import ascii_lowercase, ascii_uppercase, digits
    from fractions import gcd
    def input(): return sys.stdin.readline().strip()
    def STR(): return input()
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def S_MAP(): return map(str, input().split())
    def LIST(): return list(map(int, input().split()))
    def S_LIST(): return list(map(str, input().split()))
    sys.setrecursionlimit(10 ** 9)
    inf = sys.maxsize
    mod = 10 ** 9 + 7
     
    n, m = MAP()
    red = [False for _ in range(n)]
    bal = [1 for _ in range(n)]
    red[0] = 1
    for i in range(m):
        x, y = MAP()
        if red[x - 1]:
            red[y - 1] = True
            if bal[x - 1] == 1:
                red[x - 1] = False
        bal[x - 1] -= 1
        bal[y - 1] += 1
    print(sum(red))

Submission status: Runtime Error

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

ans = [1] * (n)
ans[0] = 1
ball = [0] * (n)
ball[0] = 1
for i in range(m):
    x, y = xy[i]
    ans[y-1] += 1
    ans[x-1] -= 1
    if ball[x-1]:
      ball[y-1] = 1
    if ans[x-1] == 0:
      ball[x-1] = 0
      
print(sum(cnt))

Submission status: Runtime Error

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

ans = [0] * N

def dfs(depth, lst):
    if depth == M:
        for i in range(N):
            if lst[i][0] == 1:
                global ans
                ans[i] = 1
                return 0
    start = XY[depth][0]
    goal = XY[depth][1]
    # print(start, goal)
    # print(lst)
    if lst[start][0] == 1 and lst[start][1] == 0:
        lst[start][0] -= 1
        lst[goal][0] += 1
        dfs(depth + 1, lst)
    elif lst[start][0] == 1 and lst[start][1] > 0:
        a = copy.deepcopy(lst)
        lst[start][0] -= 1
        lst[goal][0] += 1
        dfs(depth + 1, lst)

        a[start][1] -= 1
        a[goal][1] += 1
        dfs(depth + 1, a)
    elif lst[start][0] == 0 and lst[start][1] == 0: return 0
    else:
        lst[start][1] -= 1
        lst[goal][1] += 1
        dfs(depth + 1, lst)

tmp = [[0, 1] for _ in range(N)]
tmp[0] = [1, 0]
dfs(0, tmp)

print(sum(ans))

Submission status: Runtime Error

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

x = []
y = []
for i in range(M):
  xi, yi = input().split()
  x.append(int(xi))
  y.append(int(yi))

L=[]
for i in range(N):
  L.append(1)
R=[1]
for i in range(N-1):
  R.append(0)
#print(R) 

for i in range(M):
  if R[x[i]-1]==1 and L[x[i]-1]==1:
    R[x[i]-1]=0
    L[x[i]-1]=0
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==1 and L[i]>=1:
    L[x[i]-1]=L[x[i]-1]-1
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[x[i]-1]==0 and L[x[i]-1]>=1:
    L[x[i]-1]=L[x[i]-1]-1
    L[y[i]-1]=L[y[i]-1]+1
   
    
#print('R',R,'L',L)
print(R.count(1))

Submission status: Runtime Error

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

x = []
y = []
for i in range(M):
  xi, yi = input().split()
  x.append(int(xi))
  y.append(int(yi))

L=[]
for i in range(N):
  L.append(1)
R=[1]
for i in range(N-1):
  R.append(0)
#print(R) 

for i in range(M):
  if R[x[i]-1]==1 and L[x[i]-1]==1:
    R[x[i]-1]=0
    L[x[i]-1]=0
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==1 and L[i]>=1:
    L[x[i]-1]=L[x[i]-1]-1
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[x[i]-1]==0 and L[x[i]-1]>0:
    L[y[i]-1]=L[y[i]-1]+1
   
    
#print('R',R,'L',L)
print(R.count(1))

Submission status: Runtime Error

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

x = []
y = []
for i in range(M):
  xi, yi = input().split()
  x.append(int(xi))
  y.append(int(yi))

L=[]
for i in range(N):
  L.append(1)
R=[1]
for i in range(N-1):
  R.append(0)
#print(R) 

for i in range(M):
  if R[i]==1 and L[i]==1:
    R[i]=0
    L[i]=0
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==1 and L[i]>0:
    L[i]=L[i]-1
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==0 and L[i]>0:
    L[y[i]-1]=L[y[i]-1]+1
   
    
#print(R,L)
print(R.count(1))

Submission status: Runtime Error

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

x = []
y = []
for i in range(M):
  xi, yi = input().split()
  x.append(int(xi))
  y.append(int(yi))

L=[]
for i in range(N):
  L.append(1)
R=[1]
for i in range(N-1):
  R.append(0)
#print(R) 

for i in range(M):
  if R[i]==1 and L[i]==1:
    R[i]=0
    L[i]=0
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==1 and L[i]>1:
    L[i]=L[i]-1
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[i]==0 and L[i]>0:
    L[y[i]-1]=L[y[i]-1]+1
   
    
#print(R,L)
print(R.count(1))

Submission status: Runtime Error

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

print(sum(reds))

Submission status: Runtime Error

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][0] int action and action[i][1] in action:
            N -= 1

print(N)

Submission status: Runtime Error

Solution code:
A,B =  map(int,input().split())
b = []
Zeroflag = False
count = 0
for i in range(A,B+1,1):
  b.append(i)
if 0 in b:
  zeroflag = True
for i in b:
  if i < 0:
    count += 1
if zeroflag:
  print('Zero')
elif count %2 == 0:
  print('Positive')
else:
  print('Negative')

Submission status: Runtime Error

Solution code:
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.rempve(x)
print(len(ans))

Submission status: Runtime Error

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)
      else:ans.remove(x)
print(len(ans))

Submission status: Runtime Error

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)
      else:ans.remove(x)
print(len(ans))

Submission status: Runtime Error

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())
  if not b[x]:
    continue
  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: Runtime Error

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

num_b = [i+1 for i in range(N)]
psb = [0]*N
psb[0] = 1

for i in X:
    num_b[i[0]] -= 1
    num_b[i[1]] += 1
    if num_b[i[0]] == 0:
        psb[i[0]] = 0
    if psb[i[0]] == 1:
        psb[i[1]] == 1 

print(psb.count(1))

Submission status: Runtime Error

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

num_b = [i+1 for i in range(N)]
psb = [0]*N
psb[0] = 1

for i in X:
    num_b[[i][0]] -= 1
    num_b[[i][1]] += 1
    if num_b[[i][0]] == 0:
        psb[[i][0]] = 0
    if psb[[i][0]] == 1:
        psb[[i][1]] == 1 

print(psb.count(1))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[0]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(m):
    if a[i][0] in b:
        b.append(a[i][1])
print(len(set(b)))

Submission status: Runtime Error

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.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: Runtime Error

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: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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)
    if p[0] == 1:
        p.remove(1)

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

Submission status: Runtime Error

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
    box[x] -= 1
    box[y] += 1
    if box[i] == 0:
        red[x] = False

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

Submission status: Runtime Error

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
    box[x] -= 1
    box[y] += 1
    if box[i] == 0:
        red[i] = False

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

red = [False] * M
red[0] = True
num = [1] * M

for x, y in XY:
    num[x] -= 1
    num[y] += 1
    if red[x] == True:
        red[y] = True
        if num[x] == 0:
            red[x] = False
print(sum(red))

# http://agc002.contest.atcoder.jp/data/agc/002/editorial.pdf

Submission status: Runtime Error

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] = f[y] or f[x]
print(f.count(True))

Submission status: Runtime Error

Solution code:

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

ball_list = [1 for i in range(N)]
flag_list = [False for i in range(N)]
flag_list[0] = True

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

print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair



ll solve(int N,int M,vi& x,vi& y) {
    vi p(N, 0), k(N, 1);
    p[0] = 1;
    rep(i,M){
        int fr = x[i]-1, to = y[i]-1;
        if (p[fr]) p[to] = 1;
        --k[fr]; ++k[to];
        if (k[fr] == 0) p[fr] = 0;
    }
#ifdef DEBUG
    cerr << k << endl;
    cerr << p << endl;
#endif
    int cnt = 0;
    rep(i,N){
        if (k[i] != 0) cnt += p[i];
    }
    return cnt;
}

int main() {
    int N,M; cin>>N>>M; // 2-1e5 1-1e5
    vi x(M),y(M);
    rep(i,M) cin>>x[i]>>y[i];
    cout << solve(N,M,x,y) << endl;
    return 0;
}

Submission status: Runtime Error

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**N
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: Runtime Error

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**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: Runtime Error

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**N
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)
print(sum(c))

Submission status: Runtime Error

Solution code:
    n, l = (int(s) for s in input().strip().split(' '))
    an = []
for a in range(0,l):
    an.append(input().strip().split())

box=[[1,0] for i in range(n)]
box[0][1] = 1
for move in an:
    box[int(move[0])-1][0] -= 1
    box[int(move[1])-1][0]+=1
    if box[int(move[0])-1][1] == 1:
        box[int(move[1])-1][1]= 1
    if box[int(move[0])-1][0]==0:
        box[int(move[0])-1][1]=0
print(str(sum([s[1] for s in box])))

Submission status: Runtime Error

Solution code:
L, H = map(int,input().split())
N = int(input())
A =[]
for i in range(2,N+2):
	A.append(int(input()))
for i in range(N):
	if A[i] < L:
		print(L-A[i])
	elif A[i] <= H:
		print(0)
	else:
		print(-1)

Submission status: Runtime Error

Solution code:
def main():
    n, m = map(int, stdin.readline().split())
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    a = [0] + [2] * n
    a[1] = 1
    for i in xrange(m):
        x, y = dat[i*2], dat[i*2+1]
	if a[x] == 0:
            continue
        a[y] += 2
        if a[x] & 1 and a[y] & 1 ^ 1:
            a[y] -= 1
        a[x] -= 2
	if a[x] < 0:
            a[x] = 0
    print sum(x & 1 for x in a)
main()