node_ids listlengths 4 1.4k | edge_index listlengths 1 2.22k | text listlengths 4 1.4k | source stringlengths 14 427k |
|---|---|---|---|
[
7,
12,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
4,
13,
39,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
13,
13,
4,
18,
13,
13,
13,
14,
... | [
[
5,
4
],
[
5,
15
],
[
18,
17
],
[
24,
23
],
[
4,
27
],
[
30,
29
],
[
15,
32
],
[
35,
34
],
[
35,
45
],
[
34,
48
],
[
17,
49
],
[
17,
52
],
[
45,
54
],
[
23... | [
"def main():\n n, m = list(map(int, input().split()))\n ans = set([1, ])\n balls = [1] * n\n for _ in range(m):\n x, y = list(map(int, input().split()))\n if x in ans:\n ans.add(y)\n if balls[x - 1] == 1 and x in ans:\n ans.remove(x)\n balls[x - 1] -= 1\... | def main():
n, m = list(map(int, input().split()))
ans = set([1, ])
balls = [1] * n
for _ in range(m):
x, y = list(map(int, input().split()))
if x in ans:
ans.add(y)
if balls[x - 1] == 1 and x in ans:
ans.remove(x)
balls[x - 1] -= 1
balls[y... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
2,
13,
17,
17,
0,
18,
13,
2,
13,
17,
17,
... | [
[
99,
2
],
[
99,
11
],
[
87,
13
],
[
18,
17
],
[
97,
20
],
[
90,
24
],
[
28,
27
],
[
100,
30
],
[
93,
32
],
[
93,
41
],
[
48,
43
],
[
91,
44
],
[
94,
46
],
[
... | [
"n, m = map(int, input().split())\nred = {1, }\nl = [1 for _ in range(n)]\nfor _ in range(m):\n x, y = map(int, input().split())\n l[x - 1] -= 1\n l[y - 1] += 1\n if x in red:\n red.add(y)\n if l[x - 1] == 0:\n red.discard(x)\nprint(len(red))",
"n, m = map(int, input().split()... | n, m = map(int, input().split())
red = {1, }
l = [1 for _ in range(n)]
for _ in range(m):
x, y = map(int, input().split())
l[x - 1] -= 1
l[y - 1] += 1
if x in red:
red.add(y)
if l[x - 1] == 0:
red.discard(x)
print(len(red))
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
13,
17,
0,
18,
... | [
[
105,
2
],
[
105,
11
],
[
111,
13
],
[
106,
18
],
[
93,
21
],
[
106,
26
],
[
32,
29
],
[
94,
30
],
[
35,
34
],
[
91,
37
],
[
102,
39
],
[
102,
48
],
[
53,
50
],
... | [
"n,m=map(int,input().split())\na=[1]*(n+1)\nb=[0]*(n+1)\nb[1]=1\nfor _ in range(m):\n x,y=map(int,input().split())\n a[x]-=1\n a[y]+=1\n if b[x]:b[y]=1\n if a[x]==0:b[x]=0\nans=0\nfor i,j in zip(a,b):\n ans+=(i!=0)*j\nprint(ans)",
"n,m=map(int,input().split())",
"n",
"map(int,input().split())",
"map",... | n,m=map(int,input().split())
a=[1]*(n+1)
b=[0]*(n+1)
b[1]=1
for _ in range(m):
x,y=map(int,input().split())
a[x]-=1
a[y]+=1
if b[x]:b[y]=1
if a[x]==0:b[x]=0
ans=0
for i,j in zip(a,b):
ans+=(i!=0)*j
print(ans) |
[
7,
12,
13,
0,
13,
4,
13,
39,
17,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
28,
13,
4,
13,
4,
13,
13,
0,
18,
13,
2,
18,
18,
13,
13,
17,
17,
17,
0,
18,
13,
2,
18,
18,
13,
13,
17,
17,
17,
14,
2,
18,
18,
13,
13,
... | [
[
5,
4
],
[
12,
11
],
[
94,
14
],
[
19,
18
],
[
22,
21
],
[
92,
26
],
[
37,
28
],
[
18,
29
],
[
92,
33
],
[
21,
34
],
[
48,
39
],
[
18,
40
],
[
92,
44
],
[
... | [
"def mov(xy,N):\n Box_red = set([1])\n Box = [1 for _ in range(N)]\n\n for i in range(len(xy)):\n Box[xy[i][0]-1] -= 1\n Box[xy[i][1]-1] += 1\n if xy[i][0] in Box_red:\n Box_red.add(xy[i][1])\n if Box[xy[i][0]-1] == 0:\n Box_red.discard(xy[i][0])\n\n ret... | def mov(xy,N):
Box_red = set([1])
Box = [1 for _ in range(N)]
for i in range(len(xy)):
Box[xy[i][0]-1] -= 1
Box[xy[i][1]-1] += 1
if xy[i][0] in Box_red:
Box_red.add(xy[i][1])
if Box[xy[i][0]-1] == 0:
Box_red.discard(xy[i][0])
return len(Box_red)
... |
[
7,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
41,
28,
13,
4,
18,
4,
13,
13,
4,
2,
4,
13,
13,
17,
0,
13,
13,
... | [
[
4,
3
],
[
3,
12
],
[
125,
14
],
[
125,
16
],
[
113,
18
],
[
126,
22
],
[
27,
24
],
[
114,
25
],
[
122,
29
],
[
126,
33
],
[
36,
35
],
[
120,
38
],
[
42,
41
],
... | [
"n, m = [int(w) for w in input().split()]\n\nlb = [False] * n\nlb[0] = True\nlbn = [1] * n\n\nfor i in range(m):\n x, y = [int(w)-1 for w in input().split()]\n if lb[x] and lbn[x] > 0:\n lb[y] = True\n lbn[x] -= 1\n lbn[y] += 1\n\n if lb[x] and lbn[x] == 0:\n lb[x] = False\n\nprint(len(... | n, m = [int(w) for w in input().split()]
lb = [False] * n
lb[0] = True
lbn = [1] * n
for i in range(m):
x, y = [int(w)-1 for w in input().split()]
if lb[x] and lbn[x] > 0:
lb[y] = True
lbn[x] -= 1
lbn[y] += 1
if lb[x] and lbn[x] == 0:
lb[x] = False
print(len([_ for _ in lb if _])... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
17,
2,
13,
17,
4,
13,
39,
17,
17,
0,
13,
13,
0,
18,
18,
13,
17,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
18,
13... | [
[
115,
2
],
[
115,
11
],
[
15,
14
],
[
110,
19
],
[
14,
22
],
[
112,
27
],
[
35,
30
],
[
113,
32
],
[
38,
37
],
[
116,
40
],
[
121,
42
],
[
121,
51
],
[
58,
53
],... | [
"n, m = map(int, input().split())\nd = {i: [1, 0] for i in range(1, n+1)}\nd[1][1] = 1\nfor _ in range(m):\n x, y = map(int, input().split())\n d[x][0] -= 1\n d[y][0] += 1\n if d[x][1] == 1:\n d[y][1] = 1\n if d[x][0] == 0:\n d[x][1] = 0\nans = sum(d[i][1] for i in range(1, n+1))\nprint... | n, m = map(int, input().split())
d = {i: [1, 0] for i in range(1, n+1)}
d[1][1] = 1
for _ in range(m):
x, y = map(int, input().split())
d[x][0] -= 1
d[y][0] += 1
if d[x][1] == 1:
d[y][1] = 1
if d[x][0] == 0:
d[x][1] = 0
ans = sum(d[i][1] for i in range(1, n+1))
print(ans)
|
[
7,
15,
13,
15,
13,
15,
13,
15,
13,
15,
15,
15,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
23,
13,
23,
13,
12,
13,
23,
4,
18,
13,
13,
2,
17,
17,
0,
13,
2,
2,
17,
17,
17,
0,
13,
17,
0,
13,
... | [
[
29,
29
],
[
31,
31
],
[
162,
43
],
[
171,
50
],
[
183,
53
],
[
192,
56
],
[
154,
58
],
[
192,
59
],
[
195,
61
],
[
189,
64
],
[
193,
68
],
[
180,
70
],
[
193,
74
... | [
"import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\ndef s(): return input()\ndef i(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L... | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(i... |
[
7,
12,
13,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
... | [
[
6,
5
],
[
5,
14
],
[
17,
16
],
[
17,
18
],
[
21,
20
],
[
16,
25
],
[
29,
28
],
[
16,
33
],
[
39,
36
],
[
20,
37
],
[
42,
41
],
[
18,
44
],
[
48,
47
],
[
4... | [
"def main():\n N, M = (int(_) for _ in input().split())\n haco = [1] * (N+1)\n # 0:空, 1:白のみ取り出せる, 2:赤のみ, 3:どっちもあり得る\n cc = [1] * (N+1)\n haco[1] = 2\n for i in range(M):\n x, y = (int(_) for _ in input().split())\n cc[x] -= 1\n cc[y] += 1\n if haco[x] == 1:\n ... | def main():
N, M = (int(_) for _ in input().split())
haco = [1] * (N+1)
# 0:空, 1:白のみ取り出せる, 2:赤のみ, 3:どっちもあり得る
cc = [1] * (N+1)
haco[1] = 2
for i in range(M):
x, y = (int(_) for _ in input().split())
cc[x] -= 1
cc[y] += 1
if haco[x] == 1:
haco[y] = 3 if ... |
[
7,
15,
13,
0,
13,
12,
4,
18,
4,
18,
18,
13,
13,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,... | [
[
123,
4
],
[
126,
16
],
[
124,
23
],
[
126,
25
],
[
29,
28
],
[
127,
32
],
[
114,
37
],
[
42,
41
],
[
127,
45
],
[
111,
50
],
[
56,
53
],
[
115,
54
],
[
59,
58
]... | [
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nn, m = map(int, input().split())\nmay_contain_red = [0 for _ in range(n + 1)]\nnum_of_ball = [1 for _ in range(n + 1)]\nmay_contain_red[1] = 1\nfor i in range(m):\n x, y = map(int, input().split())\n num_of_ball[x] -= 1\n num_of_ball[y] += 1\n ... | import sys
input = lambda: sys.stdin.readline().rstrip()
n, m = map(int, input().split())
may_contain_red = [0 for _ in range(n + 1)]
num_of_ball = [1 for _ in range(n + 1)]
may_contain_red[1] = 1
for i in range(m):
x, y = map(int, input().split())
num_of_ball[x] -= 1
num_of_ball[y] += 1
if may_contain_... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
18,
13,
2,
13,
... | [
[
106,
2
],
[
106,
11
],
[
112,
13
],
[
101,
17
],
[
22,
19
],
[
113,
20
],
[
115,
24
],
[
101,
28
],
[
33,
30
],
[
116,
31
],
[
36,
35
],
[
107,
38
],
[
109,
40
... | [
"N,M=map(int, input().split())\n\nprob=[0]*N\nprob[0]=1\nnum=[1]*N\nnum[0]=1\n\nfor i in range(M):\n x,y=map(int, input().split())\n if prob[x-1]==1:\n prob[y-1]=1\n num[x-1]-=1\n num[y-1]+=1\n if num[x-1]==0:\n prob[x-1]=0\nprint(sum(prob))",
"N,M=map(int, input().split())",
"N",
... | N,M=map(int, input().split())
prob=[0]*N
prob[0]=1
num=[1]*N
num[0]=1
for i in range(M):
x,y=map(int, input().split())
if prob[x-1]==1:
prob[y-1]=1
num[x-1]-=1
num[y-1]+=1
if num[x-1]==0:
prob[x-1]=0
print(sum(prob)) |
[
7,
15,
15,
15,
15,
13,
15,
13,
15,
13,
4,
18,
13,
13,
17,
0,
13,
2,
2,
17,
17,
17,
12,
13,
29,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
12,
13,
29,
4,
13,
4,
13,
0,
13,
4,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,... | [
[
176,
16
],
[
170,
43
],
[
162,
45
],
[
170,
46
],
[
173,
48
],
[
168,
52
],
[
149,
54
],
[
168,
58
],
[
63,
60
],
[
150,
61
],
[
66,
65
],
[
171,
68
],
[
155,
70
... | [
"#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]\nfrom fractions import gcd\nfrom itertools import combinations,permutations,accumulate # (string,3) 3回\n#from collections import deque\nfrom collections import deque,defaultdict,C... | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
impo... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
13,
2,
13,
17,
0,
18,
13,
2,
13,
... | [
[
89,
2
],
[
89,
11
],
[
95,
13
],
[
81,
21
],
[
86,
24
],
[
81,
28
],
[
31,
30
],
[
90,
33
],
[
92,
35
],
[
92,
44
],
[
96,
47
],
[
84,
49
],
[
57,
52
],
[
... | [
"n,m=map(int,input().split())\nl=[1]+[0]*(n+1)\na=[1]*n\nfor i in range(m):\n x,y=map(int,input().split())\n if l[x-1]:l[y-1]=1\n a[x-1]-=1;a[y-1]+=1\n if not a[x-1]:l[x-1]=0\nprint(l.count(1))",
"n,m=map(int,input().split())",
"n",
"map(int,input().split())",
"map",
"int",
"input().split()",
"().spli... | n,m=map(int,input().split())
l=[1]+[0]*(n+1)
a=[1]*n
for i in range(m):
x,y=map(int,input().split())
if l[x-1]:l[y-1]=1
a[x-1]-=1;a[y-1]+=1
if not a[x-1]:l[x-1]=0
print(l.count(1)) |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
14,
2,
18,
... | [
[
5,
4
],
[
5,
13
],
[
16,
15
],
[
4,
19
],
[
22,
21
],
[
4,
25
],
[
30,
27
],
[
15,
28
],
[
33,
32
],
[
13,
35
],
[
38,
37
],
[
38,
46
],
[
49,
48
],
[
52,... | [
"def solve():\n N, M = map(int, input().split())\n lis = [False]*N\n cnt = [1]*N\n lis[0] = True\n for i in range(M):\n x,y = map(int, input().split())\n x -= 1\n y -= 1\n if lis[x]==True:\n lis[y]=True\n if cnt[x]==1:\n lis[x]=False\n cnt[x] -= 1\n cnt[y] += 1\n ans = lis.c... | def solve():
N, M = map(int, input().split())
lis = [False]*N
cnt = [1]*N
lis[0] = True
for i in range(M):
x,y = map(int, input().split())
x -= 1
y -= 1
if lis[x]==True:
lis[y]=True
if cnt[x]==1:
lis[x]=False
cnt[x] -= 1
cnt[y] += 1
ans = lis.count(True)
return ... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
13,
2,
13,
17,
0,
18,
13,
2,
13,
... | [
[
98,
2
],
[
98,
11
],
[
110,
13
],
[
99,
21
],
[
107,
24
],
[
99,
28
],
[
31,
30
],
[
96,
33
],
[
104,
35
],
[
104,
44
],
[
111,
47
],
[
105,
49
],
[
57,
52
],
... | [
"N,M=map(int,input().split())\nR=[True]+[False]*(N-1)\nB=[1]*N\nfor i in range(M):\n x,y=map(int,input().split())\n if R[x-1]:\n R[y-1]=True\n B[x-1]-=1\n B[y-1]+=1\n if B[x-1]==0:\n R[x-1]=False\nprint(R.count(True))",
"N,M=map(int,input().split())",
"N",
"map(int,input().split()... | N,M=map(int,input().split())
R=[True]+[False]*(N-1)
B=[1]*N
for i in range(M):
x,y=map(int,input().split())
if R[x-1]:
R[y-1]=True
B[x-1]-=1
B[y-1]+=1
if B[x-1]==0:
R[x-1]=False
print(R.count(True)) |
[
7,
15,
13,
13,
15,
15,
15,
15,
15,
15,
15,
15,
15,
15,
15,
12,
13,
12,
13,
12,
13,
12,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
12,
13,
23,
13,
4,
18,
13,
13,
2,
17,
17,
0,
13,
4,
13,
17,
0,
13,
2,
2,
17,
17,
17,... | [
[
26,
25
],
[
195,
31
],
[
35,
35
],
[
230,
44
],
[
239,
49
],
[
215,
57
],
[
195,
59
],
[
215,
60
],
[
64,
63
],
[
216,
66
],
[
242,
72
],
[
78,
75
],
[
243,
76
... | [
"import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import ... | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgette... |
[
7,
15,
13,
4,
18,
13,
13,
2,
17,
17,
0,
13,
12,
2,
4,
13,
13,
17,
23,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
12,
13,
23,
13,
12,
13,
23,
13,
23,
13,
17,
0,
13,
4,
13,
17,
12,... | [
[
160,
11
],
[
32,
31
],
[
170,
37
],
[
41,
41
],
[
45,
45
],
[
48,
47
],
[
175,
50
],
[
58,
57
],
[
155,
59
],
[
58,
60
],
[
63,
62
],
[
57,
66
],
[
69,
68
],
... | [
"import sys\nsys.setrecursionlimit(10 ** 6)\n# input = sys.stdin.readline ####\nint1 = lambda x: int(x) - 1\ndef II(): return int(input())\n\ndef MI(): return map(int, input().split())\ndef MI1(): return map(int1, input().split())\n\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(in... | import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().spl... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
13,
13,
0,
18,
13,
13,... | [
[
99,
2
],
[
99,
11
],
[
87,
13
],
[
102,
16
],
[
88,
20
],
[
94,
20
],
[
90,
22
],
[
88,
26
],
[
94,
26
],
[
31,
28
],
[
91,
29
],
[
34,
33
],
[
100,
36
],
[
... | [
"n,m = map(int,input().split())\nn += 1\np = [1]*n\nr = [0]*n\nr[1] = 1\nfor i in range(m):\n x,y = map(int,input().split())\n if r[x]:\n r[y] = 1\n if p[x] == 1:\n r[x] = 0\n p[x] -= 1\n p[y] += 1\n \nprint(sum(r))",
"n,m = map(int,input().split())",
"n",
"map(int,inpu... | n,m = map(int,input().split())
n += 1
p = [1]*n
r = [0]*n
r[1] = 1
for i in range(m):
x,y = map(int,input().split())
if r[x]:
r[y] = 1
if p[x] == 1:
r[x] = 0
p[x] -= 1
p[y] += 1
print(sum(r)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
... | [
[
105,
2
],
[
105,
11
],
[
96,
13
],
[
103,
18
],
[
24,
21
],
[
97,
22
],
[
99,
26
],
[
103,
31
],
[
37,
34
],
[
100,
35
],
[
40,
39
],
[
106,
42
],
[
114,
44
],
... | [
"n,m = map(int, input().split())\nball_cnts = [1]*(n+1)\nball_cnts[0] = 0\nred_flag = [False]*(n+1)\nred_flag[1] = True\n\nfor _ in range(m):\n x,y = map(int, input().split())\n if red_flag[x]:\n red_flag[y] = True\n if ball_cnts[x] == 1:\n red_flag[x] = False\n ball_cnts[x] -= 1\n ball... | n,m = map(int, input().split())
ball_cnts = [1]*(n+1)
ball_cnts[0] = 0
red_flag = [False]*(n+1)
red_flag[1] = True
for _ in range(m):
x,y = map(int, input().split())
if red_flag[x]:
red_flag[y] = True
if ball_cnts[x] == 1:
red_flag[x] = False
ball_cnts[x] -= 1
ball_cnts[y] += 1
ans... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
40,
... | [
[
157,
2
],
[
157,
11
],
[
145,
13
],
[
155,
18
],
[
151,
21
],
[
155,
26
],
[
32,
29
],
[
146,
30
],
[
37,
34
],
[
152,
35
],
[
40,
39
],
[
158,
42
],
[
148,
44
... | [
"# 2020/08/09\n# AtCoder Grand Contest 002 - A\n\n# Input\nn, m = map(int,input().split())\nrlist = [0] * (n+1)\nwlist = [1] * (n+1) \nrlist[1] = 1\nwlist[1] = 0\n\n# Calc\nfor i in range(m):\n x, y = map(int,input().split())\n if rlist[x] >= 1:\n rlist[y] = rlist[y] + 1\n # if rlist[x] == 1 and... | # 2020/08/09
# AtCoder Grand Contest 002 - A
# Input
n, m = map(int,input().split())
rlist = [0] * (n+1)
wlist = [1] * (n+1)
rlist[1] = 1
wlist[1] = 0
# Calc
for i in range(m):
x, y = map(int,input().split())
if rlist[x] >= 1:
rlist[y] = rlist[y] + 1
# if rlist[x] == 1 and wlist[x] == 0:
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,
13,
13,
17,
... | [
[
115,
2
],
[
115,
11
],
[
121,
13
],
[
107,
17
],
[
127,
19
],
[
107,
23
],
[
28,
25
],
[
128,
26
],
[
31,
30
],
[
116,
33
],
[
112,
35
],
[
112,
44
],
[
124,
46
... | [
"n,m = map(int,input().split())\nball = [1]*n\nans = [0]*n\nans[0] = 1\n\nfor i in range(m):\n x,y = map(int,input().split())\n x -= 1\n y -= 1\n ball[x] -= 1\n ball[y] += 1\n if ans[x] == 1:\n ans[y] = 1\n if ball[x] == 0:\n ans[x] = 0\n\na = 0\nfor an in ans:\n if an == 1:\n ... | n,m = map(int,input().split())
ball = [1]*n
ans = [0]*n
ans[0] = 1
for i in range(m):
x,y = map(int,input().split())
x -= 1
y -= 1
ball[x] -= 1
ball[y] += 1
if ans[x] == 1:
ans[y] = 1
if ball[x] == 0:
ans[x] = 0
a = 0
for an in ans:
if an == 1:
a += 1
print(a) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
2,
39,
17,
40,
40,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
14,
18,
13,
13,
0,
... | [
[
98,
2
],
[
98,
11
],
[
83,
13
],
[
81,
17
],
[
95,
19
],
[
81,
28
],
[
31,
30
],
[
99,
33
],
[
92,
35
],
[
92,
44
],
[
101,
46
],
[
89,
49
],
[
96,
53
],
[
... | [
"#!/usr/bin/env python3\nn, m = map(int, input().split())\nL = [1]*n\nR = [1] + [0]*~-n\nfor _ in range(m):\n x, y = map(int, input().split())\n x -= 1;y -= 1\n if R[x]:R[y] = 1\n L[x] -= 1;L[y] += 1\n R[x] *= (L[x] > 0)\nprint(sum(R))",
"n, m = map(int, input().split())",
"n",
"map(int, input().split())... | #!/usr/bin/env python3
n, m = map(int, input().split())
L = [1]*n
R = [1] + [0]*~-n
for _ in range(m):
x, y = map(int, input().split())
x -= 1;y -= 1
if R[x]:R[y] = 1
L[x] -= 1;L[y] += 1
R[x] *= (L[x] > 0)
print(sum(R)) |
[
7,
15,
13,
0,
13,
18,
18,
13,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
13,
17,
13,
2,
13,
17,
0,
... | [
[
107,
4
],
[
110,
11
],
[
108,
18
],
[
110,
20
],
[
98,
22
],
[
111,
26
],
[
113,
28
],
[
32,
31
],
[
96,
34
],
[
116,
36
],
[
108,
43
],
[
116,
45
],
[
119,
47
... | [
"import sys\nreadline = sys.stdin.readline\n\nN,M = map(int,readline().split())\nB = [1] * N\npossible = {0}\nfor i in range(M):\n x,y = map(int,readline().split())\n x,y = x - 1,y - 1\n B[x] -= 1\n B[y] += 1\n if x in possible:\n possible.add(y)\n if x in possible and B[x] == 0:\n possible.remove(x)\n\... | import sys
readline = sys.stdin.readline
N,M = map(int,readline().split())
B = [1] * N
possible = {0}
for i in range(M):
x,y = map(int,readline().split())
x,y = x - 1,y - 1
B[x] -= 1
B[y] += 1
if x in possible:
possible.add(y)
if x in possible and B[x] == 0:
possible.remove(x)
print(len(possible)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
18,
13,
... | [
[
208,
2
],
[
208,
11
],
[
15,
14
],
[
209,
17
],
[
202,
30
],
[
205,
33
],
[
200,
38
],
[
196,
41
],
[
200,
46
],
[
52,
49
],
[
206,
50
],
[
57,
54
],
[
197,
55
... | [
"N, M = map(int, input().split())\nXYs = [list(map(int, input().split())) for _ in range(M)]\n\nflag = [0]*(N+1)\nflag2 = [0]*(N+1)\nflag[1] = 1\nflag2[1] = 1\nnum = [1]*(N+1)\n\nfor xy in XYs:\n if flag2[xy[0]]==1 and flag[xy[0]]==1:\n flag[xy[0]]=0\n flag[xy[1]]=1\n elif flag[xy[0]]==1:\n flag[xy[1]]=1... | N, M = map(int, input().split())
XYs = [list(map(int, input().split())) for _ in range(M)]
flag = [0]*(N+1)
flag2 = [0]*(N+1)
flag[1] = 1
flag2[1] = 1
num = [1]*(N+1)
for xy in XYs:
if flag2[xy[0]]==1 and flag[xy[0]]==1:
flag[xy[0]]=0
flag[xy[1]]=1
elif flag[xy[0]]==1:
flag[xy[1]]=1
if flag2[xy[0... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
... | [
[
101,
2
],
[
101,
11
],
[
86,
13
],
[
102,
18
],
[
24,
21
],
[
87,
22
],
[
98,
26
],
[
102,
31
],
[
37,
34
],
[
99,
35
],
[
40,
39
],
[
96,
42
],
[
92,
44
],
[... | [
"N,M=map(int,input().split())\nZ=[1]*(N+1)\nZ[0]=0\n\nH=[False]*(N+1)\nH[1]=True\n\nfor _ in range(M):\n X,Y=map(int,input().split())\n\n H[Y]|=H[X]\n\n Z[X]-=1\n Z[Y]+=1\n\n H[X]&=(Z[X]!=0)\nprint(sum(H))",
"N,M=map(int,input().split())",
"N",
"map(int,input().split())",
"map",
"int",
"i... | N,M=map(int,input().split())
Z=[1]*(N+1)
Z[0]=0
H=[False]*(N+1)
H[1]=True
for _ in range(M):
X,Y=map(int,input().split())
H[Y]|=H[X]
Z[X]-=1
Z[Y]+=1
H[X]&=(Z[X]!=0)
print(sum(H))
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
13,
13,
0,
18,
13,
... | [
[
106,
2
],
[
106,
11
],
[
91,
13
],
[
107,
18
],
[
97,
21
],
[
107,
26
],
[
32,
29
],
[
98,
30
],
[
35,
34
],
[
95,
37
],
[
109,
39
],
[
109,
48
],
[
98,
51
],
... | [
"n,m = map(int, input().split())\n\nboxl = [1]*(n+1)\nredl = [False]*(n+1)\nredl[1] = True\n\nfor _ in range(m):\n x,y = map(int, input().split())\n if redl[x]:\n redl[y] = True\n if boxl[x] == 1:\n redl[x] = False\n boxl[x] -= 1\n boxl[y] += 1\n\nans = 0\nfor r in redl:\n if r: ans ... | n,m = map(int, input().split())
boxl = [1]*(n+1)
redl = [False]*(n+1)
redl[1] = True
for _ in range(m):
x,y = map(int, input().split())
if redl[x]:
redl[y] = True
if boxl[x] == 1:
redl[x] = False
boxl[x] -= 1
boxl[y] += 1
ans = 0
for r in redl:
if r: ans += 1
print(ans) |
[
7,
15,
13,
0,
13,
18,
18,
13,
13,
13,
12,
13,
29,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
23,
13,
13,
23,
13,
13,
12,
13,
29,
4,
13,
4,
13,
4,
18,
4,
13,
13,
23,
13,
17,
23,
13,
13,
23,
13,
13,
12,
13,
42,
13,
29... | [
[
154,
4
],
[
27,
14
],
[
24,
17
],
[
155,
21
],
[
25,
24
],
[
28,
27
],
[
48,
33
],
[
45,
35
],
[
155,
39
],
[
43,
42
],
[
46,
45
],
[
49,
48
],
[
57,
55
],
[
... | [
"import sys\ninput = sys.stdin.readline\n\n# from collections import deque\n\ndef linput(ty=int, cnv=list):\n return cnv(map(ty, input().split()))\n\ndef vinput(rep=1, ty=int, cnv=list):\n return cnv(ty(input().rstrip()) for _ in \"*\"*rep)\n\ndef gcd(n,m):\n while m: n,m = m, n%m\n return n\n\ndef lcm(... | import sys
input = sys.stdin.readline
# from collections import deque
def linput(ty=int, cnv=list):
return cnv(map(ty, input().split()))
def vinput(rep=1, ty=int, cnv=list):
return cnv(ty(input().rstrip()) for _ in "*"*rep)
def gcd(n,m):
while m: n,m = m, n%m
return n
def lcm(n,m): return n*m//gcd(... |
[
7,
15,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
0,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
2,
13,
17,
17,
... | [
[
127,
3
],
[
127,
12
],
[
112,
14
],
[
128,
18
],
[
23,
20
],
[
113,
21
],
[
106,
25
],
[
128,
29
],
[
115,
31
],
[
35,
34
],
[
119,
37
],
[
121,
39
],
[
121,
48
... | [
"from collections import defaultdict\nn,m=map(int, input().split())\nv = [0]*n\nv[0]=1\nans = [1]*n\nfi = 1\nfor i in range(m):\n a,b=map(int, input().split())\n ans[a-1]-=1\n ans[b-1]+=1\n if v[a-1]:\n v[b-1]=1\n fi+=1\n if ans[a-1]==0:\n v[a-1]=0\n fi-=1\n\nprint(sum(v))... | from collections import defaultdict
n,m=map(int, input().split())
v = [0]*n
v[0]=1
ans = [1]*n
fi = 1
for i in range(m):
a,b=map(int, input().split())
ans[a-1]-=1
ans[b-1]+=1
if v[a-1]:
v[b-1]=1
fi+=1
if ans[a-1]==0:
v[a-1]=0
fi-=1
print(sum(v))
|
[
7,
15,
13,
0,
13,
18,
18,
13,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
4,
13,
4,
18,
13,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
... | [
[
121,
4
],
[
127,
11
],
[
122,
18
],
[
127,
20
],
[
109,
22
],
[
128,
27
],
[
33,
30
],
[
110,
31
],
[
124,
35
],
[
125,
40
],
[
45,
44
],
[
116,
47
],
[
118,
49
... | [
"import sys\ninput = sys.stdin.readline\n\n# B - Box and Ball\nN, M = map(int, input().split())\n\nboxes = [1] * (N + 1)\nboxes[0] = 0\n\nball_exists = set()\nball_exists.add(1)\n\nfor i in range(M):\n x, y = map(int, input().split())\n\n boxes[x] -= 1\n boxes[y] += 1\n \n if x in ball_exists:\n if boxes[x]... | import sys
input = sys.stdin.readline
# B - Box and Ball
N, M = map(int, input().split())
boxes = [1] * (N + 1)
boxes[0] = 0
ball_exists = set()
ball_exists.add(1)
for i in range(M):
x, y = map(int, input().split())
boxes[x] -= 1
boxes[y] += 1
if x in ball_exists:
if boxes[x] == 0:
ball_exists... |
[
7,
12,
13,
17,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
13,
0,
13,
13,
41,
28,
13,
4,
13,
13,
4,
39,
17,
0,
13,
13,
0,
18,
13,
17,
39,
17,
0,
13,
17,
28,
13,
13,
... | [
[
7,
6
],
[
6,
15
],
[
18,
17
],
[
18,
19
],
[
23,
22
],
[
19,
25
],
[
30,
29
],
[
34,
33
],
[
17,
36
],
[
42,
41
],
[
47,
44
],
[
41,
45
],
[
51,
50
],
[
4... | [
"def resolve():\n '''\n code here\n '''\n N, M = [int(item) for item in input().split()]\n queries = [[int(item)-1 for item in input().split()] for _ in range(M)]\n\n memo = [['w'] for _ in range(N)]\n memo[0] = ['r']\n is_first_0 = True\n for x, y in queries:\n if 'r' in memo[x]:\... | def resolve():
'''
code here
'''
N, M = [int(item) for item in input().split()]
queries = [[int(item)-1 for item in input().split()] for _ in range(M)]
memo = [['w'] for _ in range(N)]
memo[0] = ['r']
is_first_0 = True
for x, y in queries:
if 'r' in memo[x]:
memo... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
14,
18,
13,
13,
0,
... | [
[
116,
2
],
[
116,
11
],
[
104,
13
],
[
111,
17
],
[
22,
19
],
[
105,
20
],
[
92,
24
],
[
111,
28
],
[
31,
30
],
[
117,
33
],
[
107,
35
],
[
107,
44
],
[
113,
46
... | [
"N, M = map(int, input().split())\npossibility = [False] * N # True: 赤いボールが入っている可能性がある\npossibility[0] = True\nballs = [1] * N # 箱に入っているボールの数\nfor i in range(M):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n if possibility[x]:\n possibility[y] = True\n balls[x] -= 1\n balls[y] +=... | N, M = map(int, input().split())
possibility = [False] * N # True: 赤いボールが入っている可能性がある
possibility[0] = True
balls = [1] * N # 箱に入っているボールの数
for i in range(M):
x, y = map(int, input().split())
x -= 1
y -= 1
if possibility[x]:
possibility[y] = True
balls[x] -= 1
balls[y] += 1
if balls[... |
[
7,
12,
13,
29,
4,
13,
4,
13,
12,
13,
29,
4,
13,
13,
4,
18,
4,
13,
13,
12,
13,
29,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
12,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
29,
13,
23,
13,
12,
13,
29,
4,
18,
4,
18... | [
[
37,
36
],
[
48,
39
],
[
48,
48
],
[
71,
68
],
[
73,
69
],
[
71,
71
],
[
73,
73
],
[
79,
78
],
[
96,
81
],
[
92,
87
],
[
94,
88
],
[
92,
92
],
[
94,
94
],
[
... | [
"def getN():\n return int(input())\ndef getNM():\n return map(int, input().split())\ndef getList():\n return list(map(int, input().split()))\ndef getArray(intn):\n return [int(input()) for i in range(intn)]\ndef input():\n return sys.stdin.readline().rstrip()\ndef rand_N(ran1, ran2):\n return rand... | def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1,... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
2,
39,
17,
13,
0,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
... | [
[
129,
2
],
[
129,
11
],
[
15,
14
],
[
127,
17
],
[
117,
21
],
[
26,
25
],
[
127,
29
],
[
132,
34
],
[
120,
40
],
[
44,
43
],
[
130,
46
],
[
138,
48
],
[
138,
57
... | [
"N, M = map(int, input().split())\nball_count = [1 for _ in range(N)]\nif_red_exists = [1] + [0 for _ in range(N-1)]\ncount = 1\nfor _ in range(M):\n x, y = map(int, input().split())\n if if_red_exists[x-1]:\n # 赤が存在する場合\n if_red_exists[y-1] = 1\n if ball_count[x-1] <= 1:\n if_... | N, M = map(int, input().split())
ball_count = [1 for _ in range(N)]
if_red_exists = [1] + [0 for _ in range(N-1)]
count = 1
for _ in range(M):
x, y = map(int, input().split())
if if_red_exists[x-1]:
# 赤が存在する場合
if_red_exists[y-1] = 1
if ball_count[x-1] <= 1:
if_red_exists[x-1]... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
39,
17,
17,
0,
13,
13,
0,
18,
18,
13,
17,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,... | [
[
156,
2
],
[
156,
11
],
[
15,
14
],
[
145,
17
],
[
147,
23
],
[
31,
26
],
[
148,
28
],
[
34,
33
],
[
157,
36
],
[
138,
38
],
[
138,
47
],
[
153,
49
],
[
141,
52
... | [
"n, m = map(int, input().split())\nboxes = [[0, 1] for _ in range(n)]\nboxes[0][0] = 1\nfor _ in range(m):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n boxes[x][1] -= 1\n boxes[y][1] += 1\n if boxes[x][0] == 1:\n boxes[y][0] = 1\n else:\n if boxes[y][0] == 1:\n ... | n, m = map(int, input().split())
boxes = [[0, 1] for _ in range(n)]
boxes[0][0] = 1
for _ in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
boxes[x][1] -= 1
boxes[y][1] += 1
if boxes[x][0] == 1:
boxes[y][0] = 1
else:
if boxes[y][0] == 1:
continue
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
18,
13,
13,
4,
13,
13,
4,
18,
4,
13,
13,
18,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
... | [
[
126,
2
],
[
126,
11
],
[
138,
13
],
[
127,
17
],
[
129,
19
],
[
127,
23
],
[
26,
25
],
[
127,
28
],
[
33,
30
],
[
139,
31
],
[
25,
32
],
[
33,
41
],
[
130,
42
]... | [
"n,m = map(int,input().split())\nx_li = [0]*m\ny_li = [0]*m\nfor i in range(m):\n x_li[i],y_li[i]=map(int,input().split())\n\nmap_li = [1]*n\nred = [False]*n\nred[0]=True\n\nfor i in range(m):\n x,y = x_li[i],y_li[i]\n x,y = x-1,y-1\n if red[x]:\n red[y]=True\n map_li[x]-=1\n map_li[y]+=1\n... | n,m = map(int,input().split())
x_li = [0]*m
y_li = [0]*m
for i in range(m):
x_li[i],y_li[i]=map(int,input().split())
map_li = [1]*n
red = [False]*n
red[0]=True
for i in range(m):
x,y = x_li[i],y_li[i]
x,y = x-1,y-1
if red[x]:
red[y]=True
map_li[x]-=1
map_li[y]+=1
if map_li[x]==0:
... |
[
7,
15,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
4,
18,
13,
13,
2,
13,
17,
0,
13,
4,
18,
13,
13,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
18,
... | [
[
112,
4
],
[
112,
13
],
[
109,
15
],
[
107,
21
],
[
103,
24
],
[
107,
30
],
[
36,
33
],
[
104,
34
],
[
39,
38
],
[
113,
41
],
[
100,
43
],
[
100,
52
],
[
73,
55
... | [
"import numpy as np\n\nN,M=map(int,input().split())\nlength=np.ones(N+1)\naka=np.ones(N+1)\naka[1]=-1\n\nfor _ in range(M):\n x,y=map(int,input().split())\n if aka[x]==-1:\n aka[y]=-1\n if length[x]-1==0:\n aka[x]=1\n length[x]-=1\n length[y]+=1\n\nprint(len(aka[aka<0]))",
"import numpy as np",
"nump... | import numpy as np
N,M=map(int,input().split())
length=np.ones(N+1)
aka=np.ones(N+1)
aka[1]=-1
for _ in range(M):
x,y=map(int,input().split())
if aka[x]==-1:
aka[y]=-1
if length[x]-1==0:
aka[x]=1
length[x]-=1
length[y]+=1
print(len(aka[aka<0])) |
[
7,
15,
13,
13,
13,
13,
0,
13,
18,
18,
13,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
2,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,... | [
[
142,
7
],
[
130,
14
],
[
143,
23
],
[
130,
25
],
[
124,
27
],
[
131,
32
],
[
38,
35
],
[
125,
36
],
[
121,
40
],
[
131,
45
],
[
49,
48
],
[
119,
51
],
[
136,
53
... | [
"import sys,math,collections,itertools\ninput = sys.stdin.readline\n\nN,M=list(map(int,input().split()))\nball = [0]*(N+1)\nball[1]=1\nball_num = [1]*(N+1)\nfor i in range(M):\n x,y=map(int,input().split())\n if ball[x]==1:\n ball[y]=1\n ball_num[x]-=1\n ball_num[y]+=1\n if ball_num[x]==0:\n ... | import sys,math,collections,itertools
input = sys.stdin.readline
N,M=list(map(int,input().split()))
ball = [0]*(N+1)
ball[1]=1
ball_num = [1]*(N+1)
for i in range(M):
x,y=map(int,input().split())
if ball[x]==1:
ball[y]=1
ball_num[x]-=1
ball_num[y]+=1
if ball_num[x]==0:
ball[x]=0
... |
[
7,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
13,
14,
2,
... | [
[
128,
2
],
[
128,
13
],
[
17,
16
],
[
117,
19
],
[
122,
32
],
[
119,
35
],
[
129,
39
],
[
125,
41
],
[
129,
45
],
[
50,
47
],
[
126,
48
],
[
53,
52
],
[
123,
52
... | [
"N,M = list(map(int,input().split()))\nXY = [list(map(int,input().split())) for _ in range(M)]\nL1 = [1]*N\nL2 = [0]*N\nL2[0] = 1\nfor xy in XY:\n if L2[xy[0]-1] == 1:\n L2[xy[1]-1] = 1\n L1[xy[0]-1] -= 1\n L1[xy[1]-1] += 1\n if L1[xy[0]-1] == 0:\n L2[xy[0]-1] = 0\nprint(sum(L2))",
"N,M ... | N,M = list(map(int,input().split()))
XY = [list(map(int,input().split())) for _ in range(M)]
L1 = [1]*N
L2 = [0]*N
L2[0] = 1
for xy in XY:
if L2[xy[0]-1] == 1:
L2[xy[1]-1] = 1
L1[xy[0]-1] -= 1
L1[xy[1]-1] += 1
if L1[xy[0]-1] == 0:
L2[xy[0]-1] = 0
print(sum(L2)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
13,
0,
13,
2,
18,
... | [
[
107,
2
],
[
107,
11
],
[
15,
14
],
[
108,
17
],
[
116,
30
],
[
122,
33
],
[
105,
37
],
[
110,
39
],
[
105,
43
],
[
48,
45
],
[
123,
46
],
[
51,
50
],
[
117,
50
... | [
"n,m = map(int,input().split())\nxyl = [list(map(int,input().split())) for nesya in range(m)]\nred = [0]*n\nball = [1]*n\nred[0] = 1\nfor xy in xyl:\n x = xy[0]-1\n y = xy[1]-1\n if red[x] > 0:\n red[y] = 1\n if ball[x] == 1:\n red[x] = 0\n ball[x] -= 1\n ball[y] += 1\nprint(sum(red))",
"n,m = map... | n,m = map(int,input().split())
xyl = [list(map(int,input().split())) for nesya in range(m)]
red = [0]*n
ball = [1]*n
red[0] = 1
for xy in xyl:
x = xy[0]-1
y = xy[1]-1
if red[x] > 0:
red[y] = 1
if ball[x] == 1:
red[x] = 0
ball[x] -= 1
ball[y] += 1
print(sum(red)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
2,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
... | [
[
175,
2
],
[
175,
11
],
[
193,
13
],
[
176,
18
],
[
24,
21
],
[
194,
22
],
[
178,
26
],
[
176,
31
],
[
37,
34
],
[
179,
35
],
[
181,
39
],
[
176,
44
],
[
48,
47
... | [
"N, M = map(int, input().split())\n\nW = [1] * (N + 1)\nW[1] = 0\nR = [0] * (N + 1)\nR[1] = 1\ncnt = [1] * (N + 1)\n\nfor _ in range(M):\n fr, to = map(int, input().split())\n cnt[fr] -= 1\n cnt[to] += 1\n\n if R[fr] == 1 and W[fr] >= 1:\n R[to] = 1\n W[to] += 1\n\n if R[fr] == 1 and W[... | N, M = map(int, input().split())
W = [1] * (N + 1)
W[1] = 0
R = [0] * (N + 1)
R[1] = 1
cnt = [1] * (N + 1)
for _ in range(M):
fr, to = map(int, input().split())
cnt[fr] -= 1
cnt[to] += 1
if R[fr] == 1 and W[fr] >= 1:
R[to] = 1
W[to] += 1
if R[fr] == 1 and W[fr] == 0:
R[fr... |
[
7,
12,
13,
15,
13,
0,
13,
18,
18,
13,
13,
13,
41,
28,
13,
4,
18,
4,
18,
4,
13,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
41,
28,
... | [
[
7,
6
],
[
15,
14
],
[
6,
20
],
[
14,
26
],
[
29,
28
],
[
29,
30
],
[
33,
32
],
[
28,
36
],
[
39,
38
],
[
28,
42
],
[
47,
44
],
[
32,
45
],
[
50,
49
],
[
3... | [
"def main():\n import sys\n input = sys.stdin.readline\n N, M = [int(x) for x in input().strip().split()]\n f = [False] * N\n c = [1] * N\n f[0] = True\n \n for m in range(M):\n x, y = [int(x) for x in input().strip().split()]\n f[y-1] = f[y-1] or f[x-1]\n c[y-1] += 1\n ... | def main():
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
f = [False] * N
c = [1] * N
f[0] = True
for m in range(M):
x, y = [int(x) for x in input().strip().split()]
f[y-1] = f[y-1] or f[x-1]
c[y-1] += 1
c[x-1] -= ... |
[
7,
12,
13,
14,
18,
13,
13,
0,
18,
13,
13,
17,
14,
2,
18,
13,
13,
17,
0,
18,
13,
13,
17,
0,
18,
13,
13,
17,
0,
18,
13,
13,
17,
23,
13,
23,
13,
14,
2,
13,
17,
41,
28,
13,
4,
18,
4,
13,
13,
17,
4,
4,
13,
13,
0,
... | [
[
34,
6
],
[
11,
8
],
[
36,
10
],
[
34,
16
],
[
22,
19
],
[
34,
21
],
[
27,
24
],
[
34,
26
],
[
32,
29
],
[
36,
31
],
[
34,
34
],
[
36,
36
],
[
44,
43
],
[
... | [
"def operate(x, y):\n if is_red[x]:\n is_red[y] = True\n if num_ball[x] == 1:\n is_red[x] = False\n num_ball[x] -= 1\n num_ball[y] += 1\n\n\nif __name__ == \"__main__\":\n\n N, M = [int(x) for x in input().split(\" \")]\n num_ball = [1 for _ in range(N)]\n is_red = [True] ... | def operate(x, y):
if is_red[x]:
is_red[y] = True
if num_ball[x] == 1:
is_red[x] = False
num_ball[x] -= 1
num_ball[y] += 1
if __name__ == "__main__":
N, M = [int(x) for x in input().split(" ")]
num_ball = [1 for _ in range(N)]
is_red = [True] + [False for _ in rang... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
18,
4,
13,
17,
13,
13,
13,
31,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
13,
4,
13,
18,
13,
39,
17,
18,
13,
39,
17,
17,
0,
13,
2,
13,
17,
13,
... | [
[
109,
2
],
[
109,
15
],
[
109,
16
],
[
100,
19
],
[
107,
23
],
[
94,
25
],
[
107,
29
],
[
34,
31
],
[
95,
32
],
[
103,
50
],
[
104,
52
],
[
97,
54
],
[
98,
56
],... | [
"n, m, *XY = map(int, open(0).read().split())\nA = [1] * n\nB = [0] * n\nB[0] = 1\nfor x, y in zip(XY[::2], XY[1::2]):\n x, y = x-1, y-1\n A[x] -= 1\n A[y] += 1\n if B[x]:\n B[y] = 1\n if A[x] == 0:\n B[x] = 0\nprint(sum(B))",
"n, m, *XY = map(int, open(0).read().split())",
"n",
"map(int, open(0).r... | n, m, *XY = map(int, open(0).read().split())
A = [1] * n
B = [0] * n
B[0] = 1
for x, y in zip(XY[::2], XY[1::2]):
x, y = x-1, y-1
A[x] -= 1
A[y] += 1
if B[x]:
B[y] = 1
if A[x] == 0:
B[x] = 0
print(sum(B)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
13,
13,
0,
18,
13,
... | [
[
115,
2
],
[
115,
11
],
[
15,
14
],
[
116,
17
],
[
112,
30
],
[
106,
33
],
[
104,
37
],
[
109,
39
],
[
104,
43
],
[
48,
45
],
[
110,
46
],
[
59,
54
],
[
107,
55
... | [
"N,M = map(int,input().split())\nxy = [list(map(int,input().split())) for _ in range(M)]\n\nball_count = [1]*N\nvisited = [0]*N\nvisited[0] = 1\n\nfor x,y in xy:\n ball_count[x-1] -= 1\n ball_count[y-1] += 1\n if visited[x-1] == 1:\n visited[y-1] = 1\n if ball_count[x-1] == 0:\n visited[x-1] = 0\n\nprint(... | N,M = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(M)]
ball_count = [1]*N
visited = [0]*N
visited[0] = 1
for x,y in xy:
ball_count[x-1] -= 1
ball_count[y-1] += 1
if visited[x-1] == 1:
visited[y-1] = 1
if ball_count[x-1] == 0:
visited[x-1] = 0
print(sum(visited)) |
[
7,
15,
13,
13,
15,
15,
15,
15,
15,
15,
15,
15,
15,
15,
15,
12,
13,
12,
13,
12,
13,
12,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
12,
13,
23,
13,
4,
18,
13,
13,
2,
17,
17,
0,
13,
4,
13,
17,
0,
13,
2,
2,
17,
17,
17,... | [
[
26,
25
],
[
167,
31
],
[
35,
35
],
[
142,
44
],
[
148,
49
],
[
160,
57
],
[
167,
59
],
[
160,
60
],
[
64,
63
],
[
161,
66
],
[
176,
69
],
[
151,
71
],
[
154,
74
... | [
"import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import ... | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgette... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
... | [
[
104,
2
],
[
104,
11
],
[
15,
14
],
[
105,
18
],
[
107,
23
],
[
28,
27
],
[
105,
31
],
[
95,
36
],
[
42,
39
],
[
96,
40
],
[
45,
44
],
[
102,
47
],
[
110,
49
],
... | [
"n, m = map(int,input().split())\nnum = [1 for i in range(n+1)]\nred = [False for i in range(n+1)]\nred[1] = True\nfor i in range(m):\n x, y = map(int,input().split())\n red[y] |= red[x]\n num[x] -= 1\n num[y] += 1\n if num[x] == 0:\n red[x] = False\nprint(red.count(True))",
"n, m = map(int,input().split(... | n, m = map(int,input().split())
num = [1 for i in range(n+1)]
red = [False for i in range(n+1)]
red[1] = True
for i in range(m):
x, y = map(int,input().split())
red[y] |= red[x]
num[x] -= 1
num[y] += 1
if num[x] == 0:
red[x] = False
print(red.count(True)) |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
13,
17,
13,
2,
13,
17,
... | [
[
5,
4
],
[
5,
13
],
[
16,
15
],
[
4,
19
],
[
24,
21
],
[
15,
22
],
[
27,
26
],
[
4,
30
],
[
33,
32
],
[
13,
35
],
[
38,
37
],
[
38,
46
],
[
49,
48
],
[
37,... | [
"def solve():\n N, M = map(int, input().split())\n contains_redball = [False] * N\n contains_redball[0] = True\n balls_cnt = [1] * N\n for _ in range(M):\n x, y = map(int, input().split())\n x, y = x - 1, y - 1\n balls_cnt[x] -= 1\n balls_cnt[y] += 1\n if contains_r... | def solve():
N, M = map(int, input().split())
contains_redball = [False] * N
contains_redball[0] = True
balls_cnt = [1] * N
for _ in range(M):
x, y = map(int, input().split())
x, y = x - 1, y - 1
balls_cnt[x] -= 1
balls_cnt[y] += 1
if contains_redball[x]:
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
8,
2,
13,
17,
17,
17,
0,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
... | [
[
139,
2
],
[
139,
11
],
[
15,
14
],
[
131,
17
],
[
14,
21
],
[
127,
26
],
[
31,
30
],
[
131,
33
],
[
133,
37
],
[
41,
40
],
[
140,
43
],
[
136,
45
],
[
128,
58
]... | [
"n, m = map(int, input().split())\nl = [True if i == 0 else False for i in range(n)]\nk = [1 for i in range(n)]\nfor i in range(m):\n xy = list(map(int, input().split()))\n if l[xy[0]-1]:\n if k[xy[0]-1] > 1:\n l[xy[1]-1] = True\n else:\n l[xy[1]-1] = True\n l[xy... | n, m = map(int, input().split())
l = [True if i == 0 else False for i in range(n)]
k = [1 for i in range(n)]
for i in range(m):
xy = list(map(int, input().split()))
if l[xy[0]-1]:
if k[xy[0]-1] > 1:
l[xy[1]-1] = True
else:
l[xy[1]-1] = True
l[xy[0]-1] = False
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
18,
13,
2,
13,
17,
14,
2,
18,
13,
2,
... | [
[
145,
2
],
[
145,
11
],
[
133,
13
],
[
146,
17
],
[
22,
19
],
[
134,
20
],
[
139,
24
],
[
146,
28
],
[
31,
30
],
[
143,
33
],
[
148,
35
],
[
148,
44
],
[
134,
47
... | [
"# agc002_b.py\nN, M = map(int,input().split())\nflg = [False]*N\nflg[0] = True\ncnt = [1]*N\nfor i in range(M):\n x, y = map(int,input().split())\n if flg[x-1]:\n if cnt[x-1]>1:\n flg[y-1] = True\n elif cnt[x-1]==1:\n flg[y-1] = True\n flg[x-1] = False\n ... | # agc002_b.py
N, M = map(int,input().split())
flg = [False]*N
flg[0] = True
cnt = [1]*N
for i in range(M):
x, y = map(int,input().split())
if flg[x-1]:
if cnt[x-1]>1:
flg[y-1] = True
elif cnt[x-1]==1:
flg[y-1] = True
flg[x-1] = False
else:
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
13,
17,
0,
18,
... | [
[
119,
2
],
[
119,
11
],
[
116,
13
],
[
120,
18
],
[
104,
21
],
[
120,
26
],
[
32,
29
],
[
105,
30
],
[
35,
34
],
[
114,
37
],
[
125,
39
],
[
125,
48
],
[
53,
50
... | [
"n,m=map(int,input().split())\nquant=[1]*(n+1)\nprob=[0]*(n+1)\nprob[1]=1\nfor i in range(m):\n x,y=map(int,input().split())\n quant[x]-=1\n quant[y]+=1\n if prob[x]>0:\n prob[y]+=1\n if quant[x]==0:\n prob[x]=0\n\ncnt=0\nfor i in range(n+1):\n if prob[i]>0:\n cnt+=1\nprint(cn... | n,m=map(int,input().split())
quant=[1]*(n+1)
prob=[0]*(n+1)
prob[1]=1
for i in range(m):
x,y=map(int,input().split())
quant[x]-=1
quant[y]+=1
if prob[x]>0:
prob[y]+=1
if quant[x]==0:
prob[x]=0
cnt=0
for i in range(n+1):
if prob[i]>0:
cnt+=1
print(cnt)
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
0,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
... | [
[
128,
2
],
[
128,
11
],
[
15,
14
],
[
129,
18
],
[
119,
23
],
[
28,
27
],
[
129,
31
],
[
110,
36
],
[
42,
39
],
[
120,
40
],
[
113,
44
],
[
48,
47
],
[
117,
50
]... | [
"N, K = map(int, input().split())\nr = [False for _ in range(N+1)]\nb = [1 for _ in range(N+1)]\nr[1] = True\nr_cnt = 1\nfor _ in range(K):\n x, y = map(int, input().split())\n b[x] -= 1\n b[y] += 1\n if r[x]:\n if b[x] == 0:\n r[x] = False\n r_cnt -= 1\n if not r[y]:\n r[y] = True\n r... | N, K = map(int, input().split())
r = [False for _ in range(N+1)]
b = [1 for _ in range(N+1)]
r[1] = True
r_cnt = 1
for _ in range(K):
x, y = map(int, input().split())
b[x] -= 1
b[y] += 1
if r[x]:
if b[x] == 0:
r[x] = False
r_cnt -= 1
if not r[y]:
r[y] = True
r_cnt += 1
print(r_cn... |
[
7,
15,
13,
0,
13,
18,
18,
18,
13,
13,
13,
13,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
41,
2... | [
[
124,
4
],
[
15,
14
],
[
125,
18
],
[
14,
23
],
[
121,
25
],
[
121,
27
],
[
127,
29
],
[
119,
34
],
[
109,
37
],
[
119,
42
],
[
48,
45
],
[
110,
46
],
[
51,
50
]... | [
"# https://atcoder.jp/contests/agc002/tasks/agc002_b\nimport sys\ninput = sys.stdin.buffer.readline\n\nn, m = [int(i) for i in input().split()]\n\ncount = [1] * (n + 1) # 1-indexed\nhave_red = [0] * (n + 1) # 1-indexed\nhave_red[1] = 1\nfor _ in range(m):\n x, y = [int(i) for i in input().split()]\n if have... | # https://atcoder.jp/contests/agc002/tasks/agc002_b
import sys
input = sys.stdin.buffer.readline
n, m = [int(i) for i in input().split()]
count = [1] * (n + 1) # 1-indexed
have_red = [0] * (n + 1) # 1-indexed
have_red[1] = 1
for _ in range(m):
x, y = [int(i) for i in input().split()]
if have_red[x]:
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
13,
17,
0,
18,
... | [
[
87,
2
],
[
87,
11
],
[
78,
13
],
[
76,
18
],
[
81,
21
],
[
76,
26
],
[
32,
29
],
[
82,
30
],
[
35,
34
],
[
88,
37
],
[
90,
39
],
[
90,
48
],
[
53,
50
],
[
... | [
"n,m=map(int,input().split())\na=[1]*(n+1)\nb=[0]*(n+1)\nb[1]=1\nfor _ in range(m):\n x,y=map(int,input().split())\n a[x]-=1\n a[y]+=1\n if b[x]:b[y]=1\n if a[x]==0:b[x]=0\nprint(sum(b))",
"n,m=map(int,input().split())",
"n",
"map(int,input().split())",
"map",
"int",
"input().split()",
"().split"... | n,m=map(int,input().split())
a=[1]*(n+1)
b=[0]*(n+1)
b[1]=1
for _ in range(m):
x,y=map(int,input().split())
a[x]-=1
a[y]+=1
if b[x]:b[y]=1
if a[x]==0:b[x]=0
print(sum(b)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
39,
17,
4,
18,
13,
13,
2,
39,
17,
2,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
13,
17,
13,
2,
13,
... | [
[
113,
2
],
[
113,
11
],
[
116,
13
],
[
102,
17
],
[
107,
19
],
[
108,
24
],
[
102,
30
],
[
34,
33
],
[
114,
36
],
[
110,
38
],
[
110,
47
],
[
98,
49
],
[
96,
51
... | [
"N, M = map(int, input().split())\nbox = [1] * N\nred = [1]\nred.extend([0] * (N - 1))\n\nfor i in range(M):\n x, y = map(int, input().split())\n x, y = x - 1, y - 1\n \n if red[x] == 1:\n if box[x] == 1:\n red[x] = 0\n red[y] = 1\n \n box[x] -= 1\n box[y] += 1\n\n\npri... | N, M = map(int, input().split())
box = [1] * N
red = [1]
red.extend([0] * (N - 1))
for i in range(M):
x, y = map(int, input().split())
x, y = x - 1, y - 1
if red[x] == 1:
if box[x] == 1:
red[x] = 0
red[y] = 1
box[x] -= 1
box[y] += 1
print(sum(red))
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
39,
39,
17,
17,
28,
13,
4,
13,
2,
13,
17,
4,
18,
13,
13,
39,
17,
17,
28,
13,
4,
13,... | [
[
175,
2
],
[
175,
11
],
[
15,
14
],
[
176,
17
],
[
163,
30
],
[
166,
33
],
[
40,
39
],
[
161,
43
],
[
167,
47
],
[
54,
53
],
[
176,
56
],
[
69,
58
],
[
167,
60
]... | [
"N, M = map(int,input().split())\nz = [list(map(int,input().split())) for i in range(M)]\nbox = [[1,1]]\nfor i in range(N-1):\n box.append([0,1])\nfor i in range(M):\n box[z[i][0]-1][1] -= 1\n box[z[i][1]-1][1] += 1\n if (box[z[i][0]-1][0] == 1):\n box[z[i][1]-1][0] = 1\n if (box[z[i][0]-1][1] == 0):\n b... | N, M = map(int,input().split())
z = [list(map(int,input().split())) for i in range(M)]
box = [[1,1]]
for i in range(N-1):
box.append([0,1])
for i in range(M):
box[z[i][0]-1][1] -= 1
box[z[i][1]-1][1] += 1
if (box[z[i][0]-1][0] == 1):
box[z[i][1]-1][0] = 1
if (box[z[i][0]-1][1] == 0):
box[z[i][0]-1][0]... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,
13,
13,
17,
... | [
[
131,
2
],
[
131,
11
],
[
110,
13
],
[
132,
17
],
[
128,
19
],
[
132,
23
],
[
28,
25
],
[
111,
26
],
[
31,
30
],
[
105,
33
],
[
113,
35
],
[
113,
44
],
[
122,
46
... | [
"n,m=map(int,input().split())\ndp=[False]*n\ndp2=[1]*n\n\ndp[0]=True\n\nfor i in range(m):\n x,y=map(int,input().split())\n x-=1\n y-=1\n dp2[y]+=1\n if dp[x]==True:\n dp[y]=True\n \n dp2[x]-=1\n if dp2[x]==0:\n dp[x]=False\n \nans=0\n\nfor i in range(n):\n if dp[i]==True:\n ans+=1\n \n ... | n,m=map(int,input().split())
dp=[False]*n
dp2=[1]*n
dp[0]=True
for i in range(m):
x,y=map(int,input().split())
x-=1
y-=1
dp2[y]+=1
if dp[x]==True:
dp[y]=True
dp2[x]-=1
if dp2[x]==0:
dp[x]=False
ans=0
for i in range(n):
if dp[i]==True:
ans+=1
print(ans) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
39,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
4,
18,
13,
13,
39,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,... | [
[
126,
2
],
[
126,
11
],
[
129,
13
],
[
17,
16
],
[
121,
19
],
[
132,
21
],
[
132,
30
],
[
130,
33
],
[
138,
39
],
[
127,
43
],
[
48,
45
],
[
139,
46
],
[
135,
50
... | [
"n, m = map(int, input().split())\nxy = []\nfor _ in range(m):\n x, y = map(int, input().split())\n xy.append((x, y))\nreds = [False]*n\nreds[0] = True\nballs = [1]*n\nfor x, y in xy:\n if reds[x-1] and balls[x-1]>1:\n reds[y-1] = True\n elif reds[x-1]:\n reds[y-1] = True\n reds[x-1... | n, m = map(int, input().split())
xy = []
for _ in range(m):
x, y = map(int, input().split())
xy.append((x, y))
reds = [False]*n
reds[0] = True
balls = [1]*n
for x, y in xy:
if reds[x-1] and balls[x-1]>1:
reds[y-1] = True
elif reds[x-1]:
reds[y-1] = True
reds[x-1] = False
ball... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
39,
17,
17,
0,
13,
13,
4,
18,
13,
13,
17,
39,
17,
17,
0,
18,
18,
13,
17,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
1... | [
[
128,
2
],
[
128,
11
],
[
15,
14
],
[
126,
17
],
[
140,
23
],
[
141,
27
],
[
39,
34
],
[
141,
36
],
[
42,
41
],
[
129,
44
],
[
131,
46
],
[
131,
55
],
[
62,
57
]... | [
"N,M = map(int,input().split())\nA = [[0,1] for _ in range(N)]\nA.insert(0,[0,0])\nA[1][0] = 1\nfor _ in range(M):\n x,y = map(int,input().split())\n A[y][1] += 1\n if A[x][0]==1:\n A[y][0]=1\n A[x][1] -= 1\n if A[x][1]==0:\n A[x][0]=0\ncnt = 0\nfor i in range(1,N+1):\n cnt += A[i][0... | N,M = map(int,input().split())
A = [[0,1] for _ in range(N)]
A.insert(0,[0,0])
A[1][0] = 1
for _ in range(M):
x,y = map(int,input().split())
A[y][1] += 1
if A[x][0]==1:
A[y][0]=1
A[x][1] -= 1
if A[x][1]==0:
A[x][0]=0
cnt = 0
for i in range(1,N+1):
cnt += A[i][0]
print(cnt) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
39,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
4,
18,
13,
13,
39,
2,
13,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
... | [
[
136,
2
],
[
136,
11
],
[
124,
13
],
[
17,
16
],
[
122,
19
],
[
130,
21
],
[
130,
30
],
[
125,
33
],
[
116,
37
],
[
131,
40
],
[
118,
43
],
[
137,
47
],
[
52,
49
... | [
"# https://atcoder.jp/contests/agc002/tasks/agc002_b\n\nn, m = map(int, input().split())\n\nxy = []\nfor _ in range(m):\n x, y = map(int, input().split())\n xy.append((x - 1, y - 1))\n\nbox = [0] * n\nbox[0] = 1\nnum = [1] * n\nfor x, y in xy:\n if box[x]:\n box[y] |= 1\n num[x] -= 1\n num[y] ... | # https://atcoder.jp/contests/agc002/tasks/agc002_b
n, m = map(int, input().split())
xy = []
for _ in range(m):
x, y = map(int, input().split())
xy.append((x - 1, y - 1))
box = [0] * n
box[0] = 1
num = [1] * n
for x, y in xy:
if box[x]:
box[y] |= 1
num[x] -= 1
num[y] += 1
if not num[x... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
18,
13,
2,
13,
17,
17,
0,
18,
13,
... | [
[
104,
2
],
[
104,
11
],
[
98,
13
],
[
96,
21
],
[
110,
24
],
[
96,
28
],
[
31,
30
],
[
105,
33
],
[
107,
35
],
[
107,
44
],
[
99,
48
],
[
108,
50
],
[
59,
54
],
... | [
"n, m = map(int, input().split())\nred = [1] + [0] * (n - 1)\nnum = [1] * n\nfor i in range(m):\n x, y = map(int, input().split())\n if red[x - 1] == 1:\n red[y - 1] = 1\n if num[x - 1] == 1:\n red[x - 1] = 0\n num[x - 1] -= 1\n num[y - 1] += 1\n \nprint(sum(red))",
"n, m =... | n, m = map(int, input().split())
red = [1] + [0] * (n - 1)
num = [1] * n
for i in range(m):
x, y = map(int, input().split())
if red[x - 1] == 1:
red[y - 1] = 1
if num[x - 1] == 1:
red[x - 1] = 0
num[x - 1] -= 1
num[y - 1] += 1
print(sum(red)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
18,
4,
13,
17,
13,
13,
13,
31,
13,
41,
28,
13,
4,
13,
13,
4,
21,
22,
17,
17,
22,
17,
17,
0,
13,
13,
0,
18,
18,
13,
17,
17,
17,
28,
13,
13,
4,
13,
31,
2,
39,
4,
13,
13,
17,
0,
... | [
[
116,
2
],
[
116,
15
],
[
116,
16
],
[
21,
20
],
[
114,
23
],
[
122,
33
],
[
41,
36
],
[
123,
38
],
[
110,
55
],
[
119,
58
],
[
123,
63
],
[
111,
64
],
[
72,
67
... | [
"N, M, *xy = map(int, open(0).read().split())\nboxes = [{\"count\": 1, \"red\": False} for _ in range(N)]\nboxes[0][\"red\"] = True\n\nfor x, y in zip(*[iter(xy)] * 2):\n x -= 1\n y -= 1\n if boxes[x][\"red\"]:\n boxes[y][\"red\"] = True\n if boxes[x][\"count\"] == 1:\n boxes[x][\"... | N, M, *xy = map(int, open(0).read().split())
boxes = [{"count": 1, "red": False} for _ in range(N)]
boxes[0]["red"] = True
for x, y in zip(*[iter(xy)] * 2):
x -= 1
y -= 1
if boxes[x]["red"]:
boxes[y]["red"] = True
if boxes[x]["count"] == 1:
boxes[x]["red"] = False
boxes[x]["... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,
13,
13,
17,
... | [
[
107,
2
],
[
107,
11
],
[
101,
13
],
[
105,
17
],
[
110,
19
],
[
105,
23
],
[
28,
25
],
[
111,
26
],
[
31,
30
],
[
108,
33
],
[
98,
35
],
[
98,
44
],
[
92,
46
],... | [
"n,m=map(int, input().split())\nball=[1]*n\nred=[False]*n\nred[0]=True\nfor i in range(m):\n x, y=map(int, input().split())\n x-=1\n y-=1\n ball[x]-=1\n ball[y]+=1\n if red[x]:\n red[y]=True\n if ball[x]==0:\n red[x]=False\n\nprint(red.count(True))",
"n,m=map(int, input(... | n,m=map(int, input().split())
ball=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
x, y=map(int, input().split())
x-=1
y-=1
ball[x]-=1
ball[y]+=1
if red[x]:
red[y]=True
if ball[x]==0:
red[x]=False
print(red.count(True)) |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
28,
13,
13,
0,
13,
... | [
[
5,
4
],
[
5,
13
],
[
16,
15
],
[
4,
19
],
[
22,
21
],
[
4,
25
],
[
30,
27
],
[
21,
28
],
[
34,
33
],
[
13,
36
],
[
50,
49
],
[
53,
52
],
[
49,
52
],
[
56,... | [
"def main():\n n,m = map(int,input().split())\n box = [1] * n\n red = [0] * n\n red[0] += 1\n op = [list(map(int,input().split())) for _ in range(m)]\n for o in op:\n x, y = o[0]-1, o[1]-1\n if box[x] < 1:\n continue\n box[x] -= 1\n if red[x] > 0:\n ... | def main():
n,m = map(int,input().split())
box = [1] * n
red = [0] * n
red[0] += 1
op = [list(map(int,input().split())) for _ in range(m)]
for o in op:
x, y = o[0]-1, o[1]-1
if box[x] < 1:
continue
box[x] -= 1
if red[x] > 0:
red[y] = 1
... |
[
7,
15,
13,
4,
18,
13,
13,
17,
0,
13,
2,
2,
17,
17,
17,
12,
13,
29,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
12,
13,
0,
13,
4,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,... | [
[
129,
9
],
[
32,
31
],
[
133,
33
],
[
32,
34
],
[
37,
36
],
[
31,
40
],
[
43,
42
],
[
31,
46
],
[
51,
48
],
[
42,
49
],
[
54,
53
],
[
34,
56
],
[
59,
58
],
[
... | [
"#from statistics import median\n#import collections\n#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]\n#from itertools import combinations # (string,3) 3回\n#from collections import deque\n#import collections.defaultdict\n#import bisect\n#\n# d = m - k[i] - k[j]\n# if kk[bise... | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_righ... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
17,
2,
13,
17,
4,
13,
39,
17,
17,
0,
13,
13,
0,
18,
13,
17,
39,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
18,
18... | [
[
134,
2
],
[
134,
11
],
[
15,
14
],
[
135,
19
],
[
14,
22
],
[
128,
27
],
[
33,
30
],
[
129,
31
],
[
38,
37
],
[
123,
40
],
[
137,
42
],
[
137,
51
],
[
129,
56
]... | [
"N,M = map(int,input().split())\nC = {i:[0,1] for i in range(1,N+1)}\nC[1] = [1,1]\nfor _ in range(M):\n x,y = map(int,input().split())\n if C[x][0]==1:\n C[y][0]=1\n C[y][1] += 1\n C[x][1] -= 1\n if C[x][1]==0:\n C[x][0]=0\ncnt = 0\nfor i in range(1,N+1):\n if C[i][0]==1:\n c... | N,M = map(int,input().split())
C = {i:[0,1] for i in range(1,N+1)}
C[1] = [1,1]
for _ in range(M):
x,y = map(int,input().split())
if C[x][0]==1:
C[y][0]=1
C[y][1] += 1
C[x][1] -= 1
if C[x][1]==0:
C[x][0]=0
cnt = 0
for i in range(1,N+1):
if C[i][0]==1:
cnt += 1
print(cnt) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
41,
28,
13,
4,
13,
13,
4,
17,
... | [
[
147,
2
],
[
147,
11
],
[
15,
14
],
[
148,
17
],
[
153,
30
],
[
35,
34
],
[
136,
37
],
[
156,
41
],
[
47,
44
],
[
157,
45
],
[
51,
50
],
[
136,
53
],
[
141,
57
]... | [
"N,M = map(int,input().split())\n\nmoves = [list(map(int,input().split())) for i in range(M)]\nisRed = [False for i in range(N)]\nisRed[0] = True\nBall = [1 for i in range(N)]\n\nfor i in range(M):\n p = moves[i][0] - 1\n q = moves[i][1] - 1\n\n if isRed[p] == True:\n isRed[q] = True\n Ball[p... | N,M = map(int,input().split())
moves = [list(map(int,input().split())) for i in range(M)]
isRed = [False for i in range(N)]
isRed[0] = True
Ball = [1 for i in range(N)]
for i in range(M):
p = moves[i][0] - 1
q = moves[i][1] - 1
if isRed[p] == True:
isRed[q] = True
Ball[p] -= 1
Bal... |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
17,
28,
13,
... | [
[
5,
4
],
[
5,
13
],
[
17,
16
],
[
13,
19
],
[
33,
32
],
[
36,
35
],
[
4,
39
],
[
42,
41
],
[
4,
45
],
[
50,
47
],
[
41,
48
],
[
53,
52
],
[
56,
55
],
[
13,... | [
"#!/usr/bin/env python3\n\ndef main():\n N, M = map(int, input().split())\n xy = [list(map(int, input().split())) for i in range(M)]\n box = [1] * N\n red_flag = [0] * N\n red_flag[0] = 1\n ans = 0\n for i in range(M):\n if red_flag[xy[i][0] - 1] == 1:\n red_flag[xy[i][1] - 1]... | #!/usr/bin/env python3
def main():
N, M = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(M)]
box = [1] * N
red_flag = [0] * N
red_flag[0] = 1
ans = 0
for i in range(M):
if red_flag[xy[i][0] - 1] == 1:
red_flag[xy[i][1] - 1] = 1
box... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,
13,
13,
17,
... | [
[
104,
2
],
[
104,
11
],
[
107,
13
],
[
105,
17
],
[
101,
19
],
[
105,
23
],
[
28,
25
],
[
102,
26
],
[
31,
30
],
[
99,
33
],
[
92,
35
],
[
92,
44
],
[
95,
46
],
... | [
"N, M = map(int, input().split())\nball_cnt = [1] * N\nexist_red = [False] * N\nexist_red[0] = True\nfor _ in range(M):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n ball_cnt[x] -= 1\n ball_cnt[y] += 1\n if exist_red[x]:\n exist_red[y] = True\n if ball_cnt[x] == 0:\n exis... | N, M = map(int, input().split())
ball_cnt = [1] * N
exist_red = [False] * N
exist_red[0] = True
for _ in range(M):
x, y = map(int, input().split())
x -= 1
y -= 1
ball_cnt[x] -= 1
ball_cnt[y] += 1
if exist_red[x]:
exist_red[y] = True
if ball_cnt[x] == 0:
exist_red[x] = False
p... |
[
7,
15,
13,
0,
13,
18,
18,
13,
13,
13,
0,
13,
18,
18,
13,
13,
13,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
0,
13,
4,
13,
13... | [
[
118,
4
],
[
121,
11
],
[
21,
20
],
[
21,
29
],
[
32,
31
],
[
20,
36
],
[
40,
39
],
[
20,
44
],
[
50,
47
],
[
39,
48
],
[
53,
52
],
[
119,
59
],
[
63,
62
],
[
... | [
"import sys\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\ndef main():\n n, m = map(int, input().split())\n balls = [1] * (n + 1)\n posib = [0] * (n + 1)\n posib[1] = 1\n m = map(int, read().split())\n ab = zip(m, m)\n for x, y in ab:\n if posib[x]:\n posib[y] = 1\n ... | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, m = map(int, input().split())
balls = [1] * (n + 1)
posib = [0] * (n + 1)
posib[1] = 1
m = map(int, read().split())
ab = zip(m, m)
for x, y in ab:
if posib[x]:
posib[y] = 1
balls[y] +=... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
39,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
4,
18,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
... | [
[
131,
2
],
[
131,
11
],
[
134,
13
],
[
17,
16
],
[
120,
19
],
[
122,
21
],
[
135,
34
],
[
123,
36
],
[
125,
38
],
[
132,
42
],
[
47,
44
],
[
126,
45
],
[
128,
49
... | [
"n, m = map(int,input().split())\nall_li = []\nfor _ in range(m):\n li = list(map(int,input().split()))\n all_li.append(li)\n#print(all_li)\nflag_memo = [False]*n\nflag_memo[0] = True\n#print(flag_memo)\nkazu_li = [1]*n\n#print(kazu_li)\n\nfor a in all_li:\n kazu_li[a[0]-1] -= 1\n kazu_li[a[1]-1] += 1\n... | n, m = map(int,input().split())
all_li = []
for _ in range(m):
li = list(map(int,input().split()))
all_li.append(li)
#print(all_li)
flag_memo = [False]*n
flag_memo[0] = True
#print(flag_memo)
kazu_li = [1]*n
#print(kazu_li)
for a in all_li:
kazu_li[a[0]-1] -= 1
kazu_li[a[1]-1] += 1
if flag_memo[a[0... |
[
7,
15,
13,
4,
18,
13,
13,
2,
17,
17,
0,
13,
12,
4,
13,
4,
18,
18,
13,
13,
13,
0,
13,
12,
4,
13,
13,
4,
18,
4,
18,
18,
13,
13,
13,
13,
0,
13,
12,
4,
13,
4,
13,
0,
13,
12,
4,
18,
4,
18,
18,
13,
13,
13,
13,
0,... | [
[
176,
11
],
[
161,
22
],
[
173,
37
],
[
162,
42
],
[
164,
44
],
[
155,
56
],
[
69,
68
],
[
170,
77
],
[
162,
79
],
[
170,
80
],
[
85,
84
],
[
171,
88
],
[
93,
90
... | [
"import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninm = lambda: map(int, sys.stdin.readline().split())\ninl = lambda: list(inm())\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\nN, M... | import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, M = inm()
def solve... |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
12,
2,
4,
13,
13,
17,
23,
4,
18,
4,
13,
13,
13,
0,
18,
13,
... | [
[
5,
4
],
[
5,
13
],
[
16,
15
],
[
4,
19
],
[
22,
21
],
[
4,
25
],
[
30,
27
],
[
21,
28
],
[
33,
32
],
[
13,
35
],
[
38,
37
],
[
38,
52
],
[
57,
54
],
[
15,... | [
"def resolve():\n n, m = map(int, input().split())\n\n num_balls = [1] * n\n red_prov = [False] * n\n red_prov[0] = True\n\n for _ in range(m):\n x, y = map(lambda x: int(x) - 1, input().split())\n\n # リストnum_ballsを更新\n num_balls[x] -= 1\n num_balls[y] += 1\n\n # リス... | def resolve():
n, m = map(int, input().split())
num_balls = [1] * n
red_prov = [False] * n
red_prov[0] = True
for _ in range(m):
x, y = map(lambda x: int(x) - 1, input().split())
# リストnum_ballsを更新
num_balls[x] -= 1
num_balls[y] += 1
# リストred_provを更新
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
17,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
13,
14,
... | [
[
193,
2
],
[
193,
11
],
[
15,
14
],
[
188,
17
],
[
190,
30
],
[
196,
33
],
[
184,
36
],
[
194,
44
],
[
199,
47
],
[
194,
51
],
[
54,
53
],
[
191,
53
],
[
200,
59
... | [
"# diff 693\nn, m = map(int, input().split())\nxy = [list(map(int, input().split())) for _ in range(m)]\n# indに気を付ける\nans = 0\n\n# judについて0:red 1:white\njud = [0] + [1] * (n - 1)\nnum = [1] * n\n\nfor i in xy:\n if num[i[0] - 1] >= 2 and jud[i[0] - 1] == 0:\n jud[i[1] - 1] = 0\n num[i[0] - 1] -= 1\... | # diff 693
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]
# indに気を付ける
ans = 0
# judについて0:red 1:white
jud = [0] + [1] * (n - 1)
num = [1] * n
for i in xy:
if num[i[0] - 1] >= 2 and jud[i[0] - 1] == 0:
jud[i[1] - 1] = 0
num[i[0] - 1] -= 1
num[i[1] -... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
... | [
[
125,
2
],
[
125,
11
],
[
15,
14
],
[
120,
17
],
[
113,
30
],
[
128,
33
],
[
126,
37
],
[
122,
39
],
[
126,
43
],
[
48,
45
],
[
123,
46
],
[
51,
50
],
[
120,
53
... | [
"n,m=map(int, input().split())\nxy=[list(map(int, input().split())) for _ in range(m)]\n\nball=[1]*n\nred=[False]*n\nred[0]=True\nfor i in range(m):\n x=xy[i][0]-1\n y=xy[i][1]-1\n if red[x]:\n red[y]=True\n if ball[x]==1:\n red[x]=False\n ball[y]+=1\n ball[x]-=1\nprint(red.c... | n,m=map(int, input().split())
xy=[list(map(int, input().split())) for _ in range(m)]
ball=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
x=xy[i][0]-1
y=xy[i][1]-1
if red[x]:
red[y]=True
if ball[x]==1:
red[x]=False
ball[y]+=1
ball[x]-=1
print(red.count(True))
|
[
7,
15,
13,
0,
13,
18,
18,
13,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
... | [
[
135,
4
],
[
144,
11
],
[
136,
18
],
[
144,
20
],
[
150,
22
],
[
142,
27
],
[
129,
30
],
[
142,
35
],
[
41,
38
],
[
130,
39
],
[
44,
43
],
[
145,
46
],
[
147,
48
... | [
"import sys\ninput = sys.stdin.readline\nn,m = map(int,input().split())\nhako = [1]*(n+1)\niro = ['white']*(n+1)\niro[1] = 'red'\n\nfor _ in range(m):\n \n x,y = map(int,input().split())\n if iro[x] == 'red':\n iro[y] ='red'\n elif iro[x] == 'white' and hako[y] == 0:\n iro[y] = 'white'\n ... | import sys
input = sys.stdin.readline
n,m = map(int,input().split())
hako = [1]*(n+1)
iro = ['white']*(n+1)
iro[1] = 'red'
for _ in range(m):
x,y = map(int,input().split())
if iro[x] == 'red':
iro[y] ='red'
elif iro[x] == 'white' and hako[y] == 0:
iro[y] = 'white'
hako[x] -= 1
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
18,
13,
2,
13,
17,
17,
0,
18,
13,
... | [
[
98,
2
],
[
98,
11
],
[
110,
13
],
[
99,
17
],
[
22,
19
],
[
111,
20
],
[
101,
24
],
[
99,
28
],
[
31,
30
],
[
96,
33
],
[
107,
35
],
[
107,
44
],
[
111,
48
],
... | [
"n, m = map(int, input().split())\n\nexist = [0] * n\nexist[0] = 1\ncnt = [1] * n\nfor i in range(m):\n x, y = map(int, input().split())\n if exist[x - 1] == 1:\n exist[y - 1] = 1\n if cnt[x - 1] == 1:\n exist[x - 1] = 0\n\n \n cnt[x - 1] -= 1\n cnt[y - 1] += 1\nprint(sum(exi... | n, m = map(int, input().split())
exist = [0] * n
exist[0] = 1
cnt = [1] * n
for i in range(m):
x, y = map(int, input().split())
if exist[x - 1] == 1:
exist[y - 1] = 1
if cnt[x - 1] == 1:
exist[x - 1] = 0
cnt[x - 1] -= 1
cnt[y - 1] += 1
print(sum(exist)) |
[
7,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
... | [
[
130,
2
],
[
130,
13
],
[
17,
16
],
[
128,
19
],
[
133,
32
],
[
124,
35
],
[
131,
39
],
[
44,
41
],
[
125,
42
],
[
145,
46
],
[
131,
50
],
[
55,
52
],
[
146,
53
... | [
"n, m = list(map(int, input().split()))\nxy = [list(map(int, input().split())) for i in range(m)]\n\nans = [1] * (n)\nans[0] = 1\nball = [False] * (n)\nball[0] = True\nfor i in range(m):\n x, y = xy[i]\n ans[y-1] += 1\n ans[x-1] -= 1\n if ball[x-1]:\n ball[y-1] = True\n if ans[x-1] == 0:\n ... | n, m = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(m)]
ans = [1] * (n)
ans[0] = 1
ball = [False] * (n)
ball[0] = True
for i in range(m):
x, y = xy[i]
ans[y-1] += 1
ans[x-1] -= 1
if ball[x-1]:
ball[y-1] = True
if ans[x-1] == 0:
ball[x-1] = False
... |
[
7,
15,
13,
12,
13,
29,
18,
4,
18,
18,
13,
13,
13,
39,
17,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4... | [
[
169,
16
],
[
167,
23
],
[
169,
25
],
[
154,
27
],
[
158,
31
],
[
36,
33
],
[
155,
34
],
[
172,
38
],
[
158,
42
],
[
45,
44
],
[
170,
47
],
[
163,
49
],
[
167,
56
... | [
"import sys\n\n\ndef input():\n return sys.stdin.readline()[:-1]\n\n\nN, M = map(int, input().split())\n\nred = [0]*N\nred[0] = 1\nbox = [1]*N\nfor _ in range(M):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n\n if red[x] == 0:\n # 箱Xには赤玉がない場合\n box[x] -= 1\n box[y] += 1\... | import sys
def input():
return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
red = [0]*N
red[0] = 1
box = [1]*N
for _ in range(M):
x, y = map(int, input().split())
x -= 1
y -= 1
if red[x] == 0:
# 箱Xには赤玉がない場合
box[x] -= 1
box[y] += 1
elif red[x] == 1 and ... |
[
7,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
2,
39,
17,
17,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
2,
39,
17,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
... | [
[
5,
4
],
[
5,
13
],
[
17,
16
],
[
4,
20
],
[
26,
25
],
[
34,
33
],
[
4,
37
],
[
43,
42
],
[
50,
49
],
[
13,
52
],
[
55,
54
],
[
55,
63
],
[
92,
66
],
[
42,... | [
"def main3():\n N, M = map(int, input().split())\n\n ball = [0, 1] + [1 for i in range(N - 1)]\n rflag = [0, 1] + [0 for i in range(N - 1)] \n\n for i in range(M):\n x, y = map(int, input().split())\n\n if rflag[x] == 1:\n rflag[y] = 1\n\n ball[x] -= 1\n ball[y] +... | def main3():
N, M = map(int, input().split())
ball = [0, 1] + [1 for i in range(N - 1)]
rflag = [0, 1] + [0 for i in range(N - 1)]
for i in range(M):
x, y = map(int, input().split())
if rflag[x] == 1:
rflag[y] = 1
ball[x] -= 1
ball[y] += 1
if ba... |
[
7,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
... | [
[
104,
2
],
[
104,
13
],
[
98,
15
],
[
96,
20
],
[
101,
23
],
[
96,
28
],
[
34,
31
],
[
102,
32
],
[
37,
36
],
[
105,
39
],
[
110,
41
],
[
110,
52
],
[
57,
54
],
... | [
"n,m = list(map(int, input().split()))\n\nbox = [1] * (n+1) \nredbox = [False] * (n+1) \nredbox[1] = True\nfor _ in range(m):\n x,y = list(map(int, input().split()))\n box[x]-=1\n box[y]+=1\n if redbox[x]:\n redbox[y] = True\n if box[x]==0:\n redbox[x] = False\n# print(box)\n# pri... | n,m = list(map(int, input().split()))
box = [1] * (n+1)
redbox = [False] * (n+1)
redbox[1] = True
for _ in range(m):
x,y = list(map(int, input().split()))
box[x]-=1
box[y]+=1
if redbox[x]:
redbox[y] = True
if box[x]==0:
redbox[x] = False
# print(box)
# print(redbox)
print(su... |
[
7,
15,
12,
13,
0,
13,
12,
18,
4,
18,
13,
13,
39,
17,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
2,
39,
17,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
... | [
[
6,
5
],
[
16,
15
],
[
5,
22
],
[
16,
24
],
[
28,
27
],
[
24,
31
],
[
5,
41
],
[
45,
44
],
[
48,
47
],
[
15,
52
],
[
56,
55
],
[
15,
60
],
[
66,
63
],
[
47... | [
"from sys import stdin\n\n\ndef main():\n input = lambda: stdin.readline()[:-1]\n N, M = map(int, input().split())\n XY = [tuple(map(int, input().split())) for _ in [0] * M]\n\n box = [1] * (N + 1)\n red = [0] * (N + 1)\n box[0], red[1] = 0, 1\n for x, y in XY:\n box[x] -= 1\n box... | from sys import stdin
def main():
input = lambda: stdin.readline()[:-1]
N, M = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in [0] * M]
box = [1] * (N + 1)
red = [0] * (N + 1)
box[0], red[1] = 0, 1
for x, y in XY:
box[x] -= 1
box[y] += 1
i... |
[
7,
15,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
28,
13,
4,
18,
18,
13,
13,
13,
0,
13,
4,... | [
[
124,
4
],
[
124,
13
],
[
17,
16
],
[
113,
20
],
[
118,
25
],
[
30,
29
],
[
113,
33
],
[
121,
38
],
[
44,
41
],
[
122,
42
],
[
47,
46
],
[
115,
54
],
[
46,
60
],... | [
"import sys\nn, m = map(int, input().split())\nball = [1 for i in range(n+1)]\nbox = [0 for i in range(n+1)]\nbox[1] = 1\nfor a in sys.stdin.readlines():\n x, y = map(int, a.split())\n ball[x] -= 1\n ball[y] += 1\n if box[y] == 0 and box[x]:\n box[y] = 1\n if box[x] and ball[x] == 0:\n ... | import sys
n, m = map(int, input().split())
ball = [1 for i in range(n+1)]
box = [0 for i in range(n+1)]
box[1] = 1
for a in sys.stdin.readlines():
x, y = map(int, a.split())
ball[x] -= 1
ball[y] += 1
if box[y] == 0 and box[x]:
box[y] = 1
if box[x] and ball[x] == 0:
box[x] = 0
print... |
[
7,
15,
13,
4,
18,
13,
13,
2,
17,
17,
0,
13,
18,
18,
13,
13,
13,
12,
13,
41,
28,
13,
4,
18,
4,
13,
13,
4,
4,
13,
13,
0,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
13,
0,
13,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18... | [
[
115,
11
],
[
22,
21
],
[
116,
25
],
[
21,
30
],
[
33,
32
],
[
33,
34
],
[
38,
37
],
[
34,
40
],
[
45,
44
],
[
48,
47
],
[
32,
52
],
[
58,
55
],
[
47,
56
],
[
... | [
"import sys\n\nsys.setrecursionlimit(10 ** 8)\n\ninput = sys.stdin.readline\n\n\ndef main():\n N, M = [int(x) for x in input().split()]\n XY = [[int(x) for x in input().split()] for _ in range(M)]\n ans = [0] * (N + 1)\n ans[1] = 1\n cnt = [1] * (N + 1)\n for x, y in XY:\n if ans[x] == 1:\n... | import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N, M = [int(x) for x in input().split()]
XY = [[int(x) for x in input().split()] for _ in range(M)]
ans = [0] * (N + 1)
ans[1] = 1
cnt = [1] * (N + 1)
for x, y in XY:
if ans[x] == 1:
ans[y] =... |
[
7,
15,
13,
13,
13,
13,
13,
13,
15,
13,
12,
13,
12,
13,
12,
13,
12,
13,
12,
13,
0,
13,
4,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
2,
39,
17,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
2,
39,
17,
13,
0,
18,
... | [
[
22,
21
],
[
118,
23
],
[
22,
24
],
[
28,
27
],
[
21,
30
],
[
35,
34
],
[
42,
41
],
[
21,
44
],
[
49,
48
],
[
57,
54
],
[
48,
55
],
[
60,
59
],
[
24,
62
],
[
... | [
"import bisect,collections,copy,itertools,math,string\nimport sys\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\ndef main():\n ... | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n, m = LI()
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
13,
2,
13,
17,
18,
13,
2,
13,
17,
... | [
[
120,
2
],
[
120,
11
],
[
123,
13
],
[
115,
17
],
[
22,
19
],
[
124,
20
],
[
111,
24
],
[
115,
28
],
[
31,
30
],
[
121,
33
],
[
117,
35
],
[
117,
44
],
[
51,
46
... | [
"N, M = map(int, input().split())\n\nred = [0]*N\nred[0] = 1\n\nq = [1]*N\n\nfor _ in range(M):\n x, y = map(int, input().split())\n red[y-1] |= red[x-1]\n q[x-1] -= 1\n q[y-1] += 1\n if q[x-1] == 0:\n red[x-1] = 0\n\nprint(sum([1 for i in range(N) if q[i]>0 and red[i]]))",
"N, M = map(int, ... | N, M = map(int, input().split())
red = [0]*N
red[0] = 1
q = [1]*N
for _ in range(M):
x, y = map(int, input().split())
red[y-1] |= red[x-1]
q[x-1] -= 1
q[y-1] += 1
if q[x-1] == 0:
red[x-1] = 0
print(sum([1 for i in range(N) if q[i]>0 and red[i]])) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
17,
0,
13,
17,
0,
18,
13,
13,
17,
... | [
[
98,
2
],
[
98,
11
],
[
92,
13
],
[
99,
17
],
[
107,
19
],
[
99,
23
],
[
28,
25
],
[
108,
26
],
[
31,
30
],
[
90,
33
],
[
110,
35
],
[
110,
44
],
[
104,
46
],
... | [
"n,m=map(int,input().split())\nnuml=[1]*n\nl=[False]*n\nl[0]=True\nfor i in range(m):\n x,y=map(int,input().split())\n x-=1\n y-=1\n numl[x]-=1\n numl[y]+=1\n if l[x]:\n l[y]=True\n if numl[x]==0:\n l[x]=False\nprint(l.count(True))",
"n,m=map(int,input().split())",
"n"... | n,m=map(int,input().split())
numl=[1]*n
l=[False]*n
l[0]=True
for i in range(m):
x,y=map(int,input().split())
x-=1
y-=1
numl[x]-=1
numl[y]+=1
if l[x]:
l[y]=True
if numl[x]==0:
l[x]=False
print(l.count(True)) |
[
7,
12,
13,
0,
13,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
2,
13,
17,
0,
18,
13,
17,
17,
28,
13,
13,
0,
13,
13,
13,
14,
18,
13,
13,
0,
18,
13,
13,
17,
0,
18,
13,
13,
17,
0,
18,
13,
13,
17,
14,
2,
18,
13,
13,
... | [
[
5,
4
],
[
76,
9
],
[
13,
12
],
[
76,
17
],
[
23,
20
],
[
4,
21
],
[
26,
25
],
[
80,
25
],
[
29,
28
],
[
25,
29
],
[
29,
30
],
[
4,
33
],
[
28,
34
],
[
39,... | [
"#!/usr/bin/env python3\n\n# from numba import njit\n\n# input = stdin.readline\n\n# @njit\ndef solve(n,m,queries):\n redInBox = [False] * (n+1)\n amountOfBalls = [1] * (n+1)\n redInBox[1] = True\n \n for query in queries:\n x,y = query\n if redInBox[x]:\n redInBox[y] = True\n amountOfBalls[x... | #!/usr/bin/env python3
# from numba import njit
# input = stdin.readline
# @njit
def solve(n,m,queries):
redInBox = [False] * (n+1)
amountOfBalls = [1] * (n+1)
redInBox[1] = True
for query in queries:
x,y = query
if redInBox[x]:
redInBox[y] = True
amountOfBalls[x] -= 1
amountOf... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
... | [
[
117,
2
],
[
117,
11
],
[
15,
14
],
[
118,
18
],
[
108,
23
],
[
28,
27
],
[
118,
31
],
[
111,
36
],
[
42,
39
],
[
109,
40
],
[
47,
44
],
[
112,
45
],
[
50,
49
],... | [
"N,M = map(int,input().split())\nA = [0 for _ in range(N+1)]\nB = [1 for _ in range(N+1)]\nA[1] = 1\nB[0] = 0\nfor _ in range(M):\n x,y = map(int,input().split())\n if A[x]==1:\n A[y]=1\n B[y] += 1\n B[x] -= 1\n if B[x]==0:\n A[x] = 0\nprint(sum(A))",
"N,M = map(int,input().split())",... | N,M = map(int,input().split())
A = [0 for _ in range(N+1)]
B = [1 for _ in range(N+1)]
A[1] = 1
B[0] = 0
for _ in range(M):
x,y = map(int,input().split())
if A[x]==1:
A[y]=1
B[y] += 1
B[x] -= 1
if B[x]==0:
A[x] = 0
print(sum(A)) |
[
7,
41,
28,
13,
4,
13,
17,
4,
39,
31,
4,
13,
13,
4,
18,
13,
13,
0,
39,
13,
13,
13,
31,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
13,
13,
0,
18,
13,
2,
13,
17,
17,
0,
18,
13,
2... | [
[
4,
3
],
[
3,
15
],
[
21,
18
],
[
21,
22
],
[
89,
25
],
[
92,
36
],
[
51,
46
],
[
93,
47
],
[
58,
53
],
[
93,
54
],
[
65,
60
],
[
90,
61
],
[
90,
66
],
[
7... | [
"#!/usr/bin/env python3\n(n, m), *q = [[*map(int, i.split())] for i in open(0)]\nb = [1] + [0] * (n - 1)\nc = [1] * n\nfor x, y in q:\n c[x - 1] -= 1\n c[y - 1] += 1\n b[y - 1] |= b[x - 1]\n b[x - 1] *= c[x - 1] > 0\nprint(sum(b))",
"[*map(int, i.split())] for i in open(0)",
"for i in open(0)",
"i... | #!/usr/bin/env python3
(n, m), *q = [[*map(int, i.split())] for i in open(0)]
b = [1] + [0] * (n - 1)
c = [1] * n
for x, y in q:
c[x - 1] -= 1
c[y - 1] += 1
b[y - 1] |= b[x - 1]
b[x - 1] *= c[x - 1] > 0
print(sum(b))
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
28,
13,
4,
13,
13,
0,
18,
13,
13,
4,
13,
13,
4,
18,
4,
13,
13,
18,
13,
13,
0,
18,... | [
[
166,
2
],
[
166,
11
],
[
15,
14
],
[
167,
17
],
[
160,
21
],
[
26,
25
],
[
167,
28
],
[
157,
32
],
[
36,
35
],
[
167,
38
],
[
43,
40
],
[
161,
41
],
[
35,
42
],... | [
"n,m = map(int,input().split())\nx = [0 for _ in range(m)]\ny = [0 for _ in range(m)]\nfor i in range(m):\n x[i],y[i] = map(int,input().split())\n x[i] -= 1\n y[i] -= 1\n\nbox = [1 for _ in range(n)]\nred = [0 for _ in range(n)]\nred[0] = 1\nfor i in range(m):\n red[y[i]] = 1 if red[x[i]] else red[y[i]]... | n,m = map(int,input().split())
x = [0 for _ in range(m)]
y = [0 for _ in range(m)]
for i in range(m):
x[i],y[i] = map(int,input().split())
x[i] -= 1
y[i] -= 1
box = [1 for _ in range(n)]
red = [0 for _ in range(n)]
red[0] = 1
for i in range(m):
red[y[i]] = 1 if red[x[i]] else red[y[i]]
red[x[i]] = ... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
13,
0,
18,
13,
17,
17,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
... | [
[
141,
2
],
[
141,
11
],
[
15,
14
],
[
142,
18
],
[
138,
23
],
[
28,
27
],
[
142,
31
],
[
132,
36
],
[
42,
39
],
[
139,
40
],
[
47,
44
],
[
133,
45
],
[
50,
49
],... | [
"n, m = map(int, input().split())\nl = [1 for i in range(n+1)]\nb = [False for i in range(n+1)]\nl[1] = 1\nb[1] = True\nfor i in range(m):\n x, y = map(int, input().split())\n if b[x] == True:\n if l[x] == 1:\n b[x] = False\n b[y] = True\n l[x] -= 1\n l[y] += 1\ncnt = 0\nfor i i... | n, m = map(int, input().split())
l = [1 for i in range(n+1)]
b = [False for i in range(n+1)]
l[1] = 1
b[1] = True
for i in range(m):
x, y = map(int, input().split())
if b[x] == True:
if l[x] == 1:
b[x] = False
b[y] = True
l[x] -= 1
l[y] += 1
cnt = 0
for i in range(1, n+1):
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
12,
2,
13,
17,
23,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
18,
... | [
[
107,
2
],
[
107,
11
],
[
98,
13
],
[
105,
17
],
[
101,
19
],
[
105,
27
],
[
31,
30
],
[
108,
33
],
[
113,
35
],
[
113,
53
],
[
58,
55
],
[
102,
56
],
[
114,
57
... | [
"n, m = map(int, input().split())\nN = [1]*n\nP = [True] + [False]*(n-1)\nfor i in range(m):\n x, y = list(map(lambda tmp: tmp-1, map(int, input().split())))\n P[y] = True if P[x]==True else P[y]\n N[x] -= 1\n N[y] += 1\n P[x] = False if N[x]==0 else P[x]\nprint(sum(P))",
"n, m = map(int, input().s... | n, m = map(int, input().split())
N = [1]*n
P = [True] + [False]*(n-1)
for i in range(m):
x, y = list(map(lambda tmp: tmp-1, map(int, input().split())))
P[y] = True if P[x]==True else P[y]
N[x] -= 1
N[y] += 1
P[x] = False if N[x]==0 else P[x]
print(sum(P)) |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
... | [
[
125,
2
],
[
125,
11
],
[
15,
14
],
[
126,
17
],
[
107,
30
],
[
110,
33
],
[
117,
37
],
[
128,
39
],
[
117,
43
],
[
48,
45
],
[
129,
46
],
[
51,
50
],
[
126,
53
... | [
"N,M = map(int,input().split())\n\nXY = [list(map(int,input().split())) for _ in range(M)]\n\nball_count = [1]*N\n\nred_ball_cand = [0]*N\nred_ball_cand[0] = 1\n\nfor i in range(M):\n x,y = XY[i]\n x,y = x-1,y-1\n if 0 < red_ball_cand[x]:\n red_ball_cand[y] = 1\n \n ball_count[x] -= 1\n ... | N,M = map(int,input().split())
XY = [list(map(int,input().split())) for _ in range(M)]
ball_count = [1]*N
red_ball_cand = [0]*N
red_ball_cand[0] = 1
for i in range(M):
x,y = XY[i]
x,y = x-1,y-1
if 0 < red_ball_cand[x]:
red_ball_cand[y] = 1
ball_count[x] -= 1
ball_count[y] += 1
... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
39,
0,
13,
39,
28,
13,
4,
13,
13,
0,
13,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
4,
18,
13,
13,
2,
18,
13,
17,
17,
4,
18,
13,
13,
2,
18,
13,
17,
17,
0,
13,
2,
... | [
[
155,
2
],
[
155,
11
],
[
152,
13
],
[
170,
16
],
[
20,
19
],
[
156,
22
],
[
149,
24
],
[
153,
37
],
[
150,
41
],
[
171,
46
],
[
150,
50
],
[
161,
54
],
[
147,
58
... | [
"n,m=map(int,input().split())\nx=[]\ny=[]\nfor i in range(m):\n xy=list(map(int,input().split()))\n x.append(xy[0]-1)\n y.append(xy[1]-1)\n\nred=[0]*n\nred[0]=1\ncnt=[1]*n\n\nfor i in range(m):\n cnt[x[i]]-=1\n cnt[y[i]]+=1\n\n if red[x[i]]==1:\n red[y[i]]=1\n \n if cnt[x[i]]==0:\n ... | n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
xy=list(map(int,input().split()))
x.append(xy[0]-1)
y.append(xy[1]-1)
red=[0]*n
red[0]=1
cnt=[1]*n
for i in range(m):
cnt[x[i]]-=1
cnt[y[i]]+=1
if red[x[i]]==1:
red[y[i]]=1
if cnt[x[i]]==0:
red[x[i]]=0
ans=0
f... |
[
7,
15,
13,
15,
13,
15,
13,
15,
13,
15,
13,
15,
13,
12,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
... | [
[
17,
16
],
[
17,
25
],
[
28,
27
],
[
16,
31
],
[
33,
32
],
[
16,
36
],
[
41,
38
],
[
32,
39
],
[
44,
43
],
[
25,
46
],
[
49,
48
],
[
49,
57
],
[
32,
61
],
[
... | [
"import math\nimport collections\nimport fractions\nimport itertools\nimport functools\nimport operator\n\ndef solve():\n n, m = map(int, input().split())\n ball, can = [1]*n, [False]*n\n can[0] = True\n for _ in range(m):\n x, y = map(int, input().split())\n if can[x-1] == True:\n ... | import math
import collections
import fractions
import itertools
import functools
import operator
def solve():
n, m = map(int, input().split())
ball, can = [1]*n, [False]*n
can[0] = True
for _ in range(m):
x, y = map(int, input().split())
if can[x-1] == True:
can[y-1] = Tru... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
4,
13,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
13,
41,
28,
13,
4,
13,
13,
4,
17,
0,
13,
13,
41,
28,
13,
4,
13,
2,
13,
17,
4,
17,
0,
13,
2,
... | [
[
118,
2
],
[
118,
11
],
[
15,
14
],
[
113,
17
],
[
121,
30
],
[
35,
34
],
[
119,
37
],
[
124,
41
],
[
46,
45
],
[
119,
49
],
[
109,
54
],
[
115,
64
],
[
127,
67
... | [
"n,m=map(int,input().split())\nl=[list(map(int,input().split())) for i in range(m)]\n\nnum_l=[1 for i in range(n)]\nbit_l=[1]+[0 for i in range(n-1)]\n\nfor x,y in l:\n x-=1\n y-=1\n\n if bit_l[x]==1:\n bit_l[y]=1\n if num_l[x]==1:\n bit_l[x]=0\n num_l[x]-=1\n num_l[y]+=1\n\nprint(bit_l.count(1))",
... | n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
num_l=[1 for i in range(n)]
bit_l=[1]+[0 for i in range(n-1)]
for x,y in l:
x-=1
y-=1
if bit_l[x]==1:
bit_l[y]=1
if num_l[x]==1:
bit_l[x]=0
num_l[x]-=1
num_l[y]+=1
print(bit_l.count(1)) |
[
7,
15,
13,
15,
13,
15,
15,
15,
15,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
13,
0,
13,
4,
13,
4,
18,
13,
13,
17,
0,
13,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,... | [
[
138,
11
],
[
138,
20
],
[
123,
22
],
[
139,
26
],
[
141,
28
],
[
142,
33
],
[
117,
37
],
[
41,
40
],
[
127,
43
],
[
132,
45
],
[
132,
54
],
[
61,
56
],
[
124,
57
... | [
"#import sys\n#import numpy as np\nimport math\n#from fractions import Fraction\nimport itertools\nfrom collections import deque\nfrom collections import Counter\n#import heapq\nfrom fractions import gcd\n#input=sys.stdin.readline\nimport bisect\nn,m=map(int,input().split())\nnum=[1]*n\ns=set()\ns.add(1)\nans=1\nf... | #import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions import gcd
#input=sys.stdin.readline
import bisect
n,m=map(int,input().split())
num=[1]*n
s=set()
s.add(1)
ans=1
for i in range(m):
... |
[
7,
15,
13,
0,
13,
39,
17,
17,
17,
0,
13,
17,
0,
13,
18,
13,
13,
0,
13,
12,
4,
13,
13,
4,
18,
4,
13,
13,
0,
13,
12,
4,
13,
4,
13,
0,
13,
17,
12,
13,
0,
13,
4,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,... | [
[
205,
4
],
[
214,
10
],
[
241,
13
],
[
206,
15
],
[
215,
16
],
[
226,
18
],
[
244,
29
],
[
227,
34
],
[
235,
36
],
[
42,
41
],
[
227,
43
],
[
42,
44
],
[
47,
46
... | [
"import sys\n\ninput_methods=['clipboard','file','key']\nusing_method=0\ninput_method=input_methods[using_method]\n\ntin=lambda : map(int, input().split())\nlin=lambda : list(tin())\nmod=1000000007\n\n#+++++\n\ndef main():\n\t#a = int(input())\n\tn, m = tin()\n\t#s = input()\n\tis_red_in = [0]*n\n\tis_red_in[0] = 1... | import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
#a = int(input())
n, m = tin()
#s = input()
is_red_in = [0]*n
is_red_in[0] = 1
num_of_ball = [1] * n
fo... |
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
41,
28,
13,
4,
13,
13,
4,
13,
0,
13,
13,
0,
13,
2,
39,
17,
13,
0,
18,
13,
17,
17,
0,
13,
2,
39,
17,
13,
28,
13,
13,
13,
14,
2,
2,
18,
13,
2,
13,
17,
17,
2,
18,
13,... | [
[
125,
2
],
[
125,
11
],
[
15,
14
],
[
123,
17
],
[
128,
21
],
[
119,
24
],
[
126,
28
],
[
33,
30
],
[
120,
31
],
[
131,
35
],
[
126,
39
],
[
120,
48
],
[
132,
55
... | [
"n,m=map(int,input().split())\na=[[int(i) for i in input().split()] for i in range(m)]\n\npossibility=[False]*n\npossibility[0]=True\ncount=[1]*n\n\nfor x,y in a:\n if possibility[x-1]==True and count[x-1]>1:\n possibility[y-1]=True\n elif possibility[x-1]==True and count[x-1]==1:\n possibility[... | n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]
possibility=[False]*n
possibility[0]=True
count=[1]*n
for x,y in a:
if possibility[x-1]==True and count[x-1]>1:
possibility[y-1]=True
elif possibility[x-1]==True and count[x-1]==1:
possibility[x-1]=False
... |
[
7,
41,
28,
13,
4,
13,
17,
4,
39,
31,
4,
13,
13,
4,
18,
13,
13,
0,
39,
13,
13,
13,
31,
13,
0,
13,
2,
39,
17,
2,
39,
17,
2,
13,
17,
0,
13,
2,
39,
17,
13,
28,
13,
13,
13,
0,
18,
13,
2,
13,
17,
17,
0,
18,
13,
2... | [
[
4,
3
],
[
3,
15
],
[
21,
18
],
[
21,
22
],
[
91,
25
],
[
94,
36
],
[
51,
46
],
[
95,
47
],
[
58,
53
],
[
95,
54
],
[
65,
60
],
[
92,
61
],
[
92,
66
],
[
9... | [
"#!/usr/bin/env python3\n(n, m), *q = [[*map(int, i.split())] for i in open(0)]\nb = [1] + [0] * (n - 1)\nc = [1] * n\nfor x, y in q:\n c[x - 1] -= 1\n c[y - 1] += 1\n b[y - 1] |= b[x - 1]\n if c[x - 1] == 0:\n b[x - 1] = 0\nprint(sum(b))",
"[*map(int, i.split())] for i in open(0)",
"for i in... | #!/usr/bin/env python3
(n, m), *q = [[*map(int, i.split())] for i in open(0)]
b = [1] + [0] * (n - 1)
c = [1] * n
for x, y in q:
c[x - 1] -= 1
c[y - 1] += 1
b[y - 1] |= b[x - 1]
if c[x - 1] == 0:
b[x - 1] = 0
print(sum(b))
|
[
7,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
0,
13,
2,
39,
17,
2,
39,
17,
13,
0,
13,
4,
13,
39,
17,
28,
13,
4,
13,
13,
0,
13,
4,
13,
13,
4,
18,
4,
13,
13,
13,
14,
2,
13,
13,
4,
18,
13,
13,
13,
0,
18,
13,
13,
... | [
[
88,
2
],
[
88,
11
],
[
79,
13
],
[
83,
20
],
[
85,
22
],
[
29,
28
],
[
89,
31
],
[
94,
33
],
[
94,
42
],
[
92,
45
],
[
86,
46
],
[
86,
49
],
[
95,
51
],
[
... | [
"N,M = map(int,input().split())\n\nlisN = [0] + [1]*N\nansSet = set([1])\n\nfor _ in range(M):\n # print(ansSet,lisN)\n x,y = map(int,input().split())\n if x in ansSet:\n ansSet.add(y)\n lisN[x] -= 1\n lisN[y] += 1\n if lisN[x] == 0:\n ansSet.discard(x)\n\nprint(len(ansSet))",
"N,M... | N,M = map(int,input().split())
lisN = [0] + [1]*N
ansSet = set([1])
for _ in range(M):
# print(ansSet,lisN)
x,y = map(int,input().split())
if x in ansSet:
ansSet.add(y)
lisN[x] -= 1
lisN[y] += 1
if lisN[x] == 0:
ansSet.discard(x)
print(len(ansSet))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.