input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
from itertools import product
n,k = list(map(int, input().split()))
d = list(map(int, input().split()))
nums = []
for i in range(10):
if i not in d: nums.append(i)
m = str(n)
for i in range(len(m), len(m)+2):
for j in product(nums, repeat=i):
ans = ""
for k in j: ans += str(k)
if int(ans)... | from itertools import product
n,k = list(map(int, input().split()))
d = list(map(int, input().split()))
nums = []
for i in range(10):
if i not in d: nums.append(i)
m = len(str(n))
for i in range(m, m+2):
for j in product(nums, repeat=i):
ans = ""
for k in j: ans += str(k)
if int(ans) >= n... | p04045 |
N, K = list(map(int,input().split()))
D = list(map(int,input().split()))
OK = []
for i in range(10):
if i not in D:
OK.append(str(i))
#print(OK)
sn = str(N)
l = len(sn)
ans = N*1
Flag = 0
while Flag == 0:
sans = str(ans)
if all(sans[i] in OK for i in range(len(sans))):
Flag = 1
else:
... | N,K = list(map(int,input().split()))
A = set(map(int,input().split()))
#A = set(A)
ok = []
for i in range(10):
if i not in A:
ok.append(i)
#print(ok)
while True:
nstr = str(N)
nstr = list(nstr)
#print(nstr)
Flag = True
for x in nstr:
x = int(x)
if x in A:
Flag = False
... | p04045 |
N,K=list(map(int,input().split()))
D=set([int(i) for i in input().split()])
while any(int(j) in D for j in str(N)):
N+=1
print(N)
| N, K = list(map(int, input().split()))
D = [i for i in input().split()]
while True:
if all(n not in D for n in str(N)):
print(N)
exit()
else:
N += 1
| p04045 |
n,k= list(map(int, input().split()))
d= list(input().split())
for i in range(n,10*n+1):
x=str(i)
ans=True
for j in range(len(x)):
if x[j] in d:
ans=False
if ans:
print(i)
break
| n,k=list(map(int,input().split()))
d=list(input().split())
for i in range(n,10*n):
a=str(i)
b=len(a)
ans=True
for j in a:
if j in d:
ans=False
break
if ans:
print(i)
exit() | p04045 |
# 24
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
... | # 24
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
... | p04045 |
import itertools
n, k = input().split()
d = list(map(int, input().split()))
number = list(range(10))
number = [str(x) for x in number if x not in d]
ans = []
for v in itertools.product(number, repeat=len(n)):
if v[0] == "0": continue
if int("".join(v)) >= int(n): ans.append(int("".join(v)))
if not an... | import itertools
n,k = list(map(int, input().split()))
d = list(input().split())
d = [str(i) for i in range(10) if str(i) not in d]
ans = float("INF")
for v in itertools.product(d, repeat=len(str(n))):
if v[0] != "0" and int("".join(v)) >= n:
if ans > int("".join(v)): ans = int("".join(v))
if ans == flo... | p04045 |
n, k = list(map(int, input().split()))
dlist = [s for s in input().split()]
ans = n
while True:
blnOk = True
for d in str(ans):
if d in dlist:
blnOk = False
if blnOk:
print(ans)
exit()
else:
ans += 1
| n, k = list(map(int, input().split()))
dlist = [s for s in input().split()]
ans = n
while True:
blnOk = True
for d in str(ans):
if d in dlist:
blnOk = False
break
if blnOk:
print(ans)
exit()
else:
ans += 1
| p04045 |
a,b = list(map(int,input().split()))
li1 = set(map(int,input().split()))
li2 = {1,2,3,4,5,6,7,8,9,0}
nu = list(li1^li2)
i = 1
while True:
aa = list(str(a))
aa = [int(x) for x in aa]
if set(aa).issubset(set(nu)):
print(a)
break
a += i | n,k = list(map(int,input().split()))
L = list(map(int,input().split()))
num = [1,2,3,4,5,6,7,8,9,0]
li = list(set(num).difference(set(L)))
flag = False
while True:
n = str(n)
for i in range(len(n)):
if int(n[i]) in li:
flag = True
else:
flag= False
... | p04045 |
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
#使うことのできるリストの作成
d = []
for i in range(10):
if i in D:
pass
else:
d += [i]
def check(i): #数値iがdのリストだけで書くことができるかを判定
I = str(i) #文字列に変換
# print (I)
n = len(I) #桁数の取得
for j in range(n): #全桁で確認... | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
#使うことのできるリストの作成
d = []
for i in range(10):
if i in D:
pass
else:
d += [i]
def check(i): #数値iがdのリストだけで書くことができるかを判定
I = str(i) #文字列に変換
# print (I)
n = len(I) #桁数の取得
for j in range(n): #全桁で確認... | p04045 |
N,K = list(map(int,input().split()))
D = set(input().split())
while True:
if not set(str(N)) & D:
break
N += 1
print(N) | N,K = list(map(int,input().split()))
D = set(input().split())
for i in range(N,100000):
# 禁止文字との共通集合がなければ良い
if not D & set(str(i)):
break
print(i) | p04045 |
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
C=[]
for i in range(0,10):
if i not in D:
C.append(i)
#print(C)
for i in range(N,10**10):
cnt=0
for j in list(map(int,list(str(i)))):
if j in C:
cnt+=1
if len(str(i))==cnt:
print(i)
exit() | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
for i in range(N, 10 * N + 1):
A = list(map(int, str(i)))
flag = 1
for a in A:
if a in D:
flag = 0
break
if flag:
print(i)
exit() | p04045 |
numbers = {str(i) for i in range(10)}
N, K = list(map(int, input().split()))
*D, = list(map(str, input().split()))
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
nums = set(str(i))
if nums <= available:
print(i)
break | n, k = list(map(int, input().split()))
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 100000):
nums = set(str(i))
if nums <= available:
print(i)
break | p04045 |
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
n = N
while True:
flg = False
for Di in D:
if str(Di) in str(n):
flg = True
if not flg:
break
n += 1
print(n) | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
n = N
while True:
i = n
while i != 0:
if i % 10 in D:
break
i = i // 10
if i == 0:
break
n += 1
print(n) | p04045 |
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
n = N
while True:
i = n
while i != 0:
if i % 10 in D:
break
i = i // 10
if i == 0:
break
n += 1
print(n) | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
n = N
while True:
i = n
while i != 0:
if i % 10 in D:
break
i = int(i / 10)
if i == 0:
break
n += 1
print(n)
| p04045 |
N, K = list(map(int, input().split()))
D = input().split()
n = N
while True:
for c in str(n):
if c in D:
break
else:
break
n += 1
print(n) | N, K = list(map(int, input().split()))
D = set(input().split())
n = N
while True:
for c in str(n):
if c in D:
break
else:
break
n += 1
print(n) | p04045 |
N, K = list(map(int, input().split()))
D = set(input().split())
n = N
while True:
for c in str(n):
if c in D:
break
else:
break
n += 1
print(n) | import sys
n, k = list(map(int, input().split()))
D = [int(x) for x in input().split()]
def dfs(s: str, m: int) -> None:
if s != "" and int(s) >= n:
print(s)
sys.exit()
if len(s) == m:
return
for i in range(10):
if i not in D:
dfs(str(i) + s, ... | p04045 |
N,K = list(map(int,input().split()))
D = set(input().split())
while 1:
E = set(str(N))
if not(D&E):
print(N)
break
N+=1 | N,K = list(map(int,input().split()))
D = list(input().split())
for i in range(N,100001):
n = str(i)
k = 1
for j in n:
if j in D:
k=0
break
if k:
print(n)
break | p04045 |
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
use = [i for i in range(10)]
for _d in d:
use.remove(_d)
while True:
ok = True
s = str(n)
for i in range(len(s)):
if int(s[i]) not in use:
ok = False
break
if ok:
... | n, k = list(map(int, input().split()))
D = list(map(str, input().split()))
money = n
ok = True
while True:
for d in D:
if d in str(money):
ok = False
break
if ok:
print(money)
break
money += 1
ok = True | p04045 |
n,k = list(map(int,input().split()))
d = list(map(int,input().split()))
while True:
a = []
m = n
while m > 0:
a.append(m % 10)
m = m // 10
j = 0
for i in range(len(a)):
if a[i] in d:
break
j += 1
if j == len(a):
... | n,k = list(map(int,input().split()))
d = list(input().split())
flg = True
while flg:
flg = False
m = list(str(n))
for i in m:
if i in d:
flg = True
break
if flg:
n += 1
print(n) | p04045 |
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=list(map(int, input().split()))
d=list(map(str, input().spli... | import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=list(map(int, input().split()))
d=list(map(str, input().spli... | p04045 |
#!/usr/bin/env python3
import sys
def solve(N: int, K: int, D: "List[int]"):
while(True):
nl = list(map(int,list(str(N))))
f = True
for i in range(len(nl)):
if(nl[i] in D):
f = False
if(f):
print(N)
exit()
... | #!/usr/bin/env python3
import sys
def solve(N: int, K: int, D: "List[int]"):
d = set(map(str, D))
while set(str(N))&d:
N += 1
print(N)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line... | p04045 |
from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)
N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]
L = [x for x in range(10) if x not in D]
ans = 10 ** 7
def dfs(n):
global ans
if n != '' and n[0] == '0':
... | from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)
N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]
L = [x for x in range(10) if x not in D]
def dfs(n):
if n != '':
if n[0] == '0':
return 10 ** 7... | p04045 |
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
def solve():
for i in range(10*N+2):
if i>=N:
s=str(i)
for j in range(len(s)):
if int(s[j]) in D: break
else:
print(i)
return 0
solve() | n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
def solve():
for i in range(10*n+2):
if i >= n:
s = str(i)
for j in range(len(s)):
if int(s[j]) in d:
break
else:
print(i)
return 0
solve()
| p04045 |
n,k = list(map(int,input().split()))
D = list(map(int,input().split()))
ans = n
while True:
for i in list(map(int, str(ans))):
if i in D:
break
else:
print (ans)
exit ()
ans += 1
| import sys
sys.setrecursionlimit(500000)
n,k = list(map(int,input().split()))
D = list(map(int,input().split()))
ans = []
def dfs(p:str):
if int(p)>=n:
ans.append(int(p))
return
if len(p)>len(str(n))+1:
return
for i in range(10):
if not i in D:
... | p04045 |
# coding: utf-8;
def main():
num = [0,1,2,3,4,5,6,7,8,9]
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
usable_num = list(set(num) - set(d))
while True:
if len(set(map(int, str(n))) - set(usable_num)) == 0:
break
else:
... | # coding: utf-8;
def main():
num = [0,1,2,3,4,5,6,7,8,9]
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
usable_num = list(set(num) - set(d))
while True:
f = True
for a in str(n):
if int(a) not in usable_num:
f = Fa... | p04045 |
N, K = list(map(int, input().split())) # 標準入力
D = list(map(int, input().split())) # 嫌いな数字のリスト
D_str = list(map(str, D))
m = N
while True:
for n in str(m):
if n in D_str:
break
else: # breakされなかったら実行される
print(m)
break
m += 1 | N, K = list(map(int, input().split()))
D=input().split()
ans=N
while True:
for i in str(ans):
if i in D:
break
else:
print(ans)
exit()
ans +=1 | p04045 |
def main():
n,k=list(map(int,input().split(' ')))
d = list(input().split(' '))
for i in range(n,10*n+1):
if not set(list(str(i)))&set(d):
print(i)
break
main() | def main():
n,k=list(map(int,input().split(' ')))
d = input().split(' ')
for i in range(n,10*n+1):
if not set(list(str(i)))&set(d):
print(i)
break
if __name__=='__main__':
main() | p04045 |
def main():
from sys import stdin
n,k = list(map(int,stdin.readline().rstrip().split()))
Ds = set(map(int,stdin.readline().rstrip().split()))
ans = n
while True:
num = ans
numset = set()
while num != 0:
r = num%10
num = num//10
... | import io,sys
sys.setrecursionlimit(10**6)
def main():
n,k = list(map(int,input().split()))
D = list(map(int,input().split()))
while True:
temp = n
num = []
while temp > 0:
num.append(temp%10)
temp//=10
flag = True
for... | p04045 |
#
# abc042 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
ou... | #
# abc042 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
ou... | p04045 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_... | p04045 |
N, K = list(map(int, input().split()))
D = set(input().split())
frag = True
ans = 0
N = N-1
for i in range(0, 1000000):
N += 1
if len(set(str(N)) & D) == 0:
ans = N
frag = False
break
print(N)
| import sys
N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = 0
now = N
for j in range(10**6):
for i in list(str(now)):
if i in D:
now += 1
break
else:
print(now)
sys.exit() | p04045 |
N, K = list(map(int, input().split()))
D = [int(i) for i in input().split()]
num = N
flag = True
while flag:
for i in D:
if str(i) in str(num):
num += 1
break
else:
print(num)
flag = False
| N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = N
for i in range(N, 100001):
if set(list(str(i))) & set(D):
gg = 1
else:
print(i)
break | p04045 |
numbers = {str(i) for i in range(10)}
N, K = list(map(int, input().split()))
*D, = list(map(str, input().split()))
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
nums = set(str(i))
if nums <= available:
print(i)
break
| def problem_c():
N, K = list(map(int, input().split()))
D = list(map(str, input().split()))
numbers = {str(i) for i in range(10)}
availables = set(numbers) - set(D)
for i in range(N, 100000):
nums = set(str(i))
if nums <= availables:
print(i)
return... | p04045 |
N, K = list(map(int, input().split()))
D = input().split()
for n in range(N, 10 * N):
if all([c not in D for c in str(n)]):
print(n)
break | N, K = input().split()
D = input().split()
E = [str(x) for x in range(10) if str(x) not in D]
n = len(N)
next_digit = [(str(d), 0) if str(d) not in D else None for d in range(10)]
for i in range(9, -1, -1):
if next_digit[i] is None:
j = (i + 1) % 10
while next_digit[j] is None:
... | p04045 |
def inpl(): return input().split()
n, k = list(map(int, inpl()))
d = inpl()
x = n
while True:
flg = True
for c in str(x):
if c in d:
flg = False
break
if flg:
break
x += 1
print(x) | def main():
import sys
sys.setrecursionlimit(10 ** 7)
N, K = list(map(int, input().split()))
D = set(map(int, input().split()))
digits = {x for x in range(10)}
digits -= D
# print(digits)
digits = sorted(digits)
def dfs(pay):
if pay >= N:
return p... | p04045 |
n,k=list(map(int,input().split()))
d=list(map(int,input().split()))
nmax=100000
for nn in range(n,nmax):
ns=list(str(nn))
yn="yes"
for nsi in ns:
# print(nn,nsi,(nsi in d))
if int(nsi) in d:
yn="no"
break
if yn=="no":
continue
else:
... | n,k=list(map(int,input().split()))
d=set(input().split())
for nn in range(n,10*n+1):
if len(set(str(nn)) & d)==0:
print(nn)
break
| p04045 |
n,k = list(map(int,input().split()))
ng = set(input().split())
while len(set(str(n))&ng):
n+=1
print(n)
| n,k = list(map(int,input().split()))
ng = set(list(input().split()))
while True:
if len(set(str(n))&ng)==0:
break
else:
n+=1
print(n) | p04045 |
N, K = list(map(int, input().split()))
D = set(input().split())
while True:
l = list(str(N))
for x in l:
if x in D:
N += 1
break
else:
print(N)
exit()
| N, K = list(map(int, input().split()))
D = set(map(int, input().split()))
safe = set(range(10)) - D
def test(N):
return set((int(x) for x in str(N))) <= safe
def F(N):
while N % 10:
if test(N):
return N
N += 1
N //= 10
x = F(N)
y = min(safe)
return 10... | p04045 |
N, K = list(map(int,input().split()))
D = list(map(str, input().split()))
while True:
S = str(N)
t = 0
for x in S:
if x not in D:
t += 1
if t == len(S):
print(S)
break
else:
N += 1
| import sys, math
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = list(map(int,input().split()))
D = set(list(input().split()))
for k in range(N,100001):
s = str(k)
f = 0
for e in s:
if e in D:
f = 1
brea... | p04045 |
import sys, math
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = list(map(int,input().split()))
D = set(list(input().split()))
for k in range(N,100001):
s = str(k)
f = 0
for e in s:
if e in D:
f = 1
brea... | import sys, math
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = list(map(int,input().split()))
D = set(input().split())
for ans in range(N,1000000):
f = 0
for e in str(ans):
if e in D:
f = 1
break
if f ... | p04045 |
#n=int(input())
ans=10**6
n,k=list(map(int,input().split()))
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
if i not in p:
s.append(str(i))
for a in s+['0']:
for b in s:
for c in s:
for d in s:
for e in s:
x=lis... | n,k=list(map(int,input().split()))
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
if i not in p:
s.append(str(i))
for x in range(n,10*n):
flg=True
for d in str(x):
if d not in s:
flg=False
if flg:
print(x)
break | p04045 |
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
while True:
flag = 1
N_str = list(str(N))
for s in N_str:
if int(s) in D:
flag = 0
break
if flag:
print(N)
break
N += 1 | N,K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
ans = 0
for i in range(N, 10*N+1):
res = i
while res > 0:
digit = res % 10
if digit in D:
break
res //= 10
if res <= 0:
ans = i
... | p04045 |
n,k=list(map(int,input().split()))
d=input().split()
while 1:
t=0
p=list(str(n))
q=len(p)
for c in range(q):
if t==1:
break
for b in range(k):
if p[c]==d[b]:
n=n+10**c
t=1
break
if t==0:
br... | n,k=list(map(int,input().split()))
d=input().split()
while 1:
t=0
p=list(str(n))
q=len(p)
for c in range(q):
if t==1:
break
for b in range(k):
if p[c]==d[b]:
n=n+1
t=1
break
if t==0:
break
... | p04045 |
n,k=list(map(int,input().split()))
d=input().split()
while 1:
t=0
p=list(str(n))
q=len(p)
for c in range(q):
if t==1:
break
for b in range(k):
if p[c]==d[b]:
n=n+1
t=1
break
if t==0:
break
... | n,k=list(map(int,input().split()))
d=input().split()
while 1:
t=0
p=list(str(n))
q=len(p)
for c in range(q):
if t==1:
break
for b in range(k):
if p[c]==d[b]:
r=10**(q-c-1)
n=int(n/r+1)*r
t=1
... | p04045 |
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D
for i in range(N,100*N):
if use >= set(str(i)):
print(i)
break
| N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D
for i in range(N,88889):
if use >= set(str(i)):
print(i)
break
| p04045 |
import itertools
N,K = list(map(int,input().split()))
D = list(map(int,input().split()))
A = []
for i in range(10):
if i not in D:
A.append(i)
cmin = 100000
k = len(str(N))
for i in range(k,6):
for x in itertools.product(A,repeat=i):
cnt = 0
for j in range(i):
cn... | N,K = list(map(int,input().split()))
D = list(map(int,input().split()))
E = []
for i in range(10):
if i not in D:
E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
if int(N[i]) not in E:
ind = i
break
if ind==len(N):
print(N)
else:
flag = 0... | p04045 |
def main():
num = list(map(int,input().split()))
bad = list(map(int,input().split()))
while True :
flg=0
for i in range(0,len(str(num[0]))):
stnum=str(num[0])
if int(stnum[i]) in bad:
flg=1
break
if flg==1:
num[0]+=1
continue
else:
break
print((num[0]))
... | def main():
num = list(map(int,input().split()))
bad = list(map(str,input().split()))
while True :
flg=0
for i in range(0,len(str(num[0]))):
stnum=str(num[0])
if stnum[i] in bad:
flg=1
break
if flg==1:
num[0]+=1
continue
else:
break
print((num[0]))
mai... | p04045 |
n, k=list(map(int, input().split()))
d = list(input().split())
i=n
while True:
count = 0
for j in range(k):
if d[j] in str(i):
count += 1
if count == 0:
print(i)
break
else:
i += 1 | n,k = list(map(int, input().split()))
d = list(input().split())
while True:
c=0
for i in range(k):
if d[i] in str(n):
c+=1
if c==0:
print(n)
break
else:
n+=1
| p04045 |
def abc042_c():
price, len_hate_set = list(map(int, input().split()))
hate_set = set([int(i) for i in input().split()])
while True:
if all([int(x) in set(range(0, 10)) - hate_set for x in [int(str(price)[i]) for i in range(len(str(price)))]]) and price >= price:
return price
... | def abc042_c():
price, len_hate_set = list(map(int, input().split()))
hate_set = set([int(i) for i in input().split()])
usable_set = set(range(0, 10)) - hate_set
while True:
if all([int(x) in usable_set for x in [int(str(price)[i]) for i in range(len(str(price)))]]) and price >= price... | p04045 |
def no_dislike_number(num, D):
for dislike in D:
if dislike in num:
return False
return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True):
if no_dislike_number(str(num), D):
print(num)
break
num += 1 | def no_dislike_number(num, D):
for digit in num:
if digit in D:
return False
return True
# for dislike in D:
# if dislike in num:
# return False
# return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True)... | p04045 |
# encoding: utf-8
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
Db = []
for Di in range(10):
if Di not in D: Db.append(Di)
# print("#", Db)
for level in range(6):
if N // (10 ** level) < 1: break
# print("#", level)
memo = [None] * ((level + 1) * 10000)
de... | # encoding: utf-8
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
Db = []
for Di in range(10):
if Di not in D: Db.append(Di)
# print("#", Db)
for level in range(6):
if N // (10 ** level) < 1: break
# print("#", level)
# memo = [None] * ((level + 1) * 10000)
... | p04045 |
#!/use/bin/env python3
(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
like = []
ans = n
while (1):
c = True
b = n
while (b != 0):
b = b // 10
d = b % 10
if d in a:
c = False
break
if (c):
... | #!/use/bin/env python3
(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
like = []
ans = n
b = n
while (1):
c = True
b = n
while (b != 0):
d = b % 10
b = b // 10
if d in a:
c = False
break
if (c):
... | p04045 |
n,k = list(map(int,input().split()))
dls = list(map(int,input().split()))
while 1:
s = list(map(int,list(str(n))))
for i in dls:
if i in s:
break
else:
print(n)
exit()
n += 1 | n,k = list(map(int,input().split()))
dls = list(map(str,input().split()))
while 1:
s = str(n)
for i in dls:
if i in s:
break
else:
print(n)
exit()
n += 1 | p04045 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | p04045 |
def slove():
import sys
import collections
input = sys.stdin.readline
n, k = list(map(int, input().rstrip('\n').split()))
d = collections.defaultdict(int)
for i in list(map(int, input().rstrip('\n').split())):
d[i]
for i in range(n, 10 ** 10):
s = str(i)
b =... | import sys
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, k = list(map(int, input().rstrip('\n').split()))
d = collections.defaultdict(int)
for v in list(map(int, input().rstrip('\n').split())):
d[str(v)]
for i in range(n, 10 ** 10):
... | p04045 |
N,K = list(map(int,input().split()))
D = set(input().split())
while len(set(str(N))&D)>0:
N+=1
print(N) | N,K = list(map(int,input().split()))
D = set(input().split())
for n in range(N,100000):
if len(set(str(n))&D)==0:
print(n)
break | p04045 |
N,K = list(map(int,input().split()))
D = set(input().split())
for n in range(N,100000):
if len(set(str(n))&D)==0:
print(n)
break | N,K = list(map(int,input().split()))
D = set(input().split())
while len(set(str(N))&D):
N+=1
print(N) | p04045 |
N,K = list(map(int,input().split()))
D = set(input().split())
while True:
for c in str(N):
if c in D:
break
else:
print(N)
exit()
N += 1
| N,K = list(map(int,input().split()))
D = set(input().split())
while True:
for c in str(N):
if c in D:
break
else:
print(N)
exit()
N += 1
print(N) | p04045 |
N, K = list(map(int, input().split(" ")))
list_num = ["0","1","2","3","4","5","6","7","8","9"]
D = input().split(" ")
use_num = list(set(list_num) - set(D))
ok = []
for a in use_num:
ok.append(a)
for b in use_num:
ok.append(a+b)
for c in use_num:
ok.append(a+b+c)
... | def main():
N, K = list(map(int, input().split()))
D = list(input().split())
for i in range(N,100000):
a = str(i)
flag = True
for d in D:
if d in a:
flag = False
break
if flag:
print(i)
exit... | p04045 |
N, K = list(map(int, input().split()))
Dset = set(input().split())
while True:
if Dset & set(str(N)) == set():
print(N)
break
else:
N += 1
| def check(num, ng):
for c in str(num):
if int(c) in ng:
return False
return True
N, K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
while True:
if check(N, D):
print(N)
break
else:
N += 1
| p04045 |
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
"""
import sys
from sys import stdin
input = stdin.readline
def solve(forbiddens, N):
forbiddens.sort()
ans = N
repeat = True
while repeat:
repeat = False
num_s = str(ans)
for... | # -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
AC
"""
import sys
from sys import stdin
input = stdin.readline
def solve(forbiddens, N):
forbiddens = set(forbiddens)
ans = N
repeat = True
while repeat:
repeat = False
num_s = str(... | p04045 |
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
def dfs(N, M, i, f):
if i == len(N):
print(*M, sep='')
exit()
if f:
dfs(N, M + [D[0]], i+1, 1)
for d in D:
if d == N[i]:
dfs(N, M+[d], i+1,... | n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
d0 = D[0]
def dfs(M, i, f):
if i == len(N):
print(*M, sep='')
exit()
if f:
dfs(M+[d0], i+1, 1)
for d in D:
if d == N[i]:
dfs(M+[d], i+1, 0... | p04045 |
S, K = list(map(int, input().split()))
Bad = list(input().split())
while 1:
if all(d not in str(S) for d in Bad):
print(S)
break
S += 1
| import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = sorted(set(range(10)) - set(Bad))
NotZero = sorted(set(OK) - set([0]))
if any(d > str(OK[-1]) for d in S):
print((str(NotZero[0]) + str(OK[0]) * len(S)))
sys.exit()
count = [0] * 10
for c in str(S):
count[ord(c) - ord... | p04045 |
def main():
N, K = list(map(int, input().split()))
D = input().split()
for i in range(N, N*10):
if len(set(list(str(i))) & set(D)) == 0:
print(i)
break
main() | n, k = list(map(int, input().split()))
d = [ int(x) for x in input().split() ]
def is_ok(x):
while x != 0:
if x % 10 in d:
return False
x //= 10
return True
money = n
while True:
if is_ok(n):
print(n)
break
n += 1
| p04045 |
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
nums = [i for i in range(10) if not i in l]
while True:
total = 0
for num in nums:
total += list(str(n)).count(str(num))
if total == len(list(str(n))):
print(n)
break
n += 1 | n, k = list(map(int, input().split()))
like = list(map(str, set(range(10)) - set(map(int, input().split()))))
while True:
count = 0
for c in str(n):
if c in like:
count += 1
if count == len(str(n)):
print(n)
break
n += 1 | p04045 |
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
zero = True
else:
zero = False
n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)
def lowest():
for i in n_oks:
for j in n_oks:
for k in n_oks:
... | n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
zero = True
else:
zero = False
n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)
def lowest():
for i in n_oks:
for j in n_oks:
for k in n_oks:
... | p04045 |
n,k = list(map(int,input().split()))
d = list(map(int,input().split()))
while 1:
for c in str(n):
if int(c) in d:
break
else:
print(n)
exit()
n += 1
| n,k=list(map(int,input().split()));d=input().split()
while 1:
for c in str(n):
if c in d:break
else:
print(n)
exit()
n += 1 | p04045 |
from collections import deque
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
like=list(range(1,10))
dislike0=False
for s in D:
if s==0:
dislike0=True
else:
like.remove(s)
like.sort()
q=deque(like)
if dislike0==False:
like.insert(0,0)
while q:
... | N,K=list(map(int,input().split()))
D=list(input().split())
while True:
for s in str(N):
if s in D:
N+=1
break
else:
print(N)
exit() | p04045 |
n,k=list(map(int,input().split()))
d=list(map(int,input().split()))
a=[]
for i in range(10):
sum=0
for x in d:
if x==i:
break
else:
sum+=1
if sum==k:
a.append(i)
a=set(a)
for i in range(n,10*n+1):
b=[]
x=len(str(i))
y=str(i)
fo... | n,k=list(map(int,input().split()))
d=set(input().split())
while len(d&set(str(n)))!=0:
n+=1
print(n) | p04045 |
N,K = list(map(int,input().split()))
D = list(map(str,list(map(int,input().split()))))
n = N
while True:
s = str(n)
S = set(list(s))
for c in S:
if c in D:
break
else:
break
n += 1
print(n) | N,K=list(map(int, input().split()))
D=set(input().split())
def check(x):
for c in str(x):
if c in D: return False
return True
ans = N
while not check(ans): ans += 1
print(ans) | p04045 |
n,k = list(map(int,input().split()))
d = input().split()
f = True
while(f):
for s in d:
if s in str(n):
_ = n
n += 1
break
else:
break
print(n) | n,k = list(map(int,input().split()))
d = list(map(int,input().split()))
while(True):
x = n
while(x):
if x%10 in d:
break
x//=10
else:
print(n)
quit(0)
n += 1 | p04045 |
N, K = list(map(int, input().split()))
D = {i for i in range(10)} - set(map(int, input().split()))
for i in range(N, 100000):
if all(j in D for j in map(int, str(i))):
print(i)
break
| N, K, *D = list(map(int, open(0).read().split()))
D = set(str(d) for d in D)
for i in range(N, 100_000):
if set(str(i)) & D:
continue
print(i)
break
| p04045 |
lst_1 = input().split()
N = lst_1[0]
K = int(lst_1[1])
lst_N = list(N)
lst_hate = input().split()
flg = True
while 1:
for i in range(len(lst_N)):
for j in range(len(lst_hate)):
if lst_N[i] == lst_hate[j]:
flg = False
break
if fl... | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
k = N
"""while k > 0:
lst.append(k % 10)
k //= 10
#lst.reverse()"""
#print(lst)
while 1:
flg = True
lst = []
N = k
while k > 0:
lst.append(k % 10)
k //= 10
lst.reverse()
# print... | p04045 |
n,k=list(map(int,input().split()))
D=set(list(map(int,input().split())))
for i in range(n,10*n):
num=set(list(map(int,str(i))))
if i>=n and len(D&num)==0:
print(i)
exit() | n,k=list(map(int,input().split()))
D=set(list(map(str,input().split())))
for i in range(n,10*n):
num=set(list(str(i)))
if i>=n and len(D&num)==0:
print(i)
exit() | p04045 |
n,k=list(map(int,input().split()))
D = list(map(str,input().split()))
x = n
while True:
y = str(x)
for i in range(len(y)):
if y[i] in D:
break
else:
ans = x
break
x += 1
print(ans) | n,k=list(map(int,input().split()))
D = list(map(str,input().split()))
x = n
while True:
y = str(x)
for i in y:
if i in D:
break
else:
ans = x
break
x += 1
print(ans) | p04045 |
# 0〜9
l=list(range(10))
# 入力
N,K=list(map(int,input().split()))
l2=list(map(int,input().split()))
ans=''
f=False
# 使用可能な数字を求める
for x in l2:
l.remove(x)
# 集合型に変換
l=set(l)
for x in range(1,1000000):
y=set(map(int,list(str(x))))
if N<=x and l.issuperset(y):
print(x)
break | # 0〜9
l=list(range(10))
# 入力
N,K=list(map(int,input().split()))
l2=list(map(int,input().split()))
# 使用可能な数字を求める
for x in l2:
l.remove(x)
# 集合型に変換
l=set(l)
# 1<=N<=10000 なので、答えは最大でも100000まで
for x in range(1,100001):
# 集合型に変換
y=set(map(int,list(str(x))))
# Nを上回る数字かつ、使える数字のみを使用している場合
if ... | p04045 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def main():
n,k=... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def main():
n,k=... | p04045 |
amount, num = list(map(int, input().split()))
hate_num_list = list(map(str, input().split()))
while(True):
check = 0
for digit in str(amount):
if digit in hate_num_list:
check += 1
if check == 0:
print(amount)
break
else:
amount += 1 | amount, num = list(map(int, input().split()))
hated_digit = list(map(str, input().split()))
while True:
check = 0
for hd in hated_digit:
if hd not in str(amount):
check += 1
else:
amount += 1
if check == num:
print(amount)
break | p04045 |
N, L = list(map(int, input().split()))
D = input().split()
ans = N
while 1:
s = str(ans)
f = 1
for i in D:
if i in s : f = 0
if f : break
ans += 1
print(ans) | def main():
N, L = list(map(int, input().split()))
D = input().split()
ans = N
while 1:
s = str(ans)
if not [1 for i in D if i in s] : break
ans += 1
print(ans)
if __name__ == '__main__':
main() | p04045 |
import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
D = list(map(int, readline().rstrip().split()))
nums = [str(i) for i in range(10)]
for d in D:
nums.remove(str(d))
for i in range(N, N*10+1):
d = str(i)
flg = T... | import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
D = set(readline().rstrip().split())
for i in range(N, N*10+1):
d = str(i)
flg = True
for e in d:
if e in D:
flg = False
br... | p04045 |
n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(10 * n):
for a in A:
if a in str(n + i):
break
else:
ans = n + i
break
print(ans) | n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(n * 10):
for j in str(n + i):
if j in A:
break
else:
print((n + i))
break | p04045 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N,K=list(map(int,input().split()))
N= str(N)
S={i for i in range(10)}
D=set(map(int,input().split()))
D=S-D
def search(N):
for i in range(len(N)):
... | import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
def main():
N,K=list(map(int,input().split()))
D=set(map(int,input().split()))
L={i for i in range(10)}
U=L-D
while True:
sn ... | p04045 |
from collections import deque
n, m = list(map(int, input().split()))
e = [int(eval(input())) for _ in range(m)]
d = deque(i for i in range(1, n+1))
for v in e[::-1]:
try:
d.remove(v)
print(v)
except ValueError:
pass
while d:
print((d.popleft())) | n, m = list(map(int, input().split()))
e = [int(eval(input())) for _ in range(m)]
b = [1] * (n+1)
for v in e[::-1]:
if b[v]:
b[v] = 0
print(v)
for i in range(1, n+1):
if b[i]:
print(i) | p00946 |
n = int(eval(input()))
G = [[] for i in range(n)]
root = 0
color_num = 0
keys = []
def get_key(n1, n2):
if n1 > n2:
return str(n2) + '-' + str(n1)
return str(n1) + '-' + str(n2)
for _ in range(n - 1):
a, b = list(map(int, input().split()))
keys.append(get_key(a - 1, b - 1))
G[a - 1].append... | n = int(eval(input()))
G = [[] for i in range(n)]
root = 0
color_num = 0
for i in range(n - 1):
a, b = list(map(int, input().split()))
G[a - 1].append((b - 1, i))
G[b - 1].append((a - 1, i))
if color_num < len(G[a - 1]):
root = a - 1
color_num = len(G[a - 1])
elif color_num < len(G[b - 1]... | p02850 |
from collections import deque
import sys
input = sys.stdin.readline
def bfs(v, N, G, E):
visited = [0]*N
queue = deque()
new_color = 1
used_color = set()
num_used_color = 0
node2colors = [set() for _ in range(N)]
queue.append(v)
visited[v] = 1
while queue:
... | from collections import deque
import sys
input = sys.stdin.readline
def bfs(v, N, G, E):
visited = [0]*N
queue = deque()
K = -1
node2color = [-1 for _ in range(N)]
queue.append(v)
visited[v] = 1
while queue:
q = queue.popleft()
color = 0
for nex in ... | p02850 |
N = int(eval(input()))
ABs = []
for i in range(N - 1):
ABs.append(tuple(map(int, input().split())))
Cs = [0] * (N + 1)
for i in range(N - 1):
Cs[ABs[i][0]] += 1
Cs[ABs[i][1]] += 1
K = max(Cs)
print(K)
ABsc = [[False] * (K + 1) for _ in range(N + 1)]
Tr = [[] for _ in range(N + 1)]
for i in r... | N = int(eval(input()))
ABs = []
for i in range(N - 1):
ABs.append(tuple(map(int, input().split())))
Cs = [0] * (N + 1)
Tr = [[] for _ in range(N + 1)]
for i in range(N - 1):
Cs[ABs[i][0]] += 1
Cs[ABs[i][1]] += 1
p = min(ABs[i][0], ABs[i][1])
c = max(ABs[i][0], ABs[i][1])
Tr[p].appen... | p02850 |
#!/usr/bin/env python3
import sys
from collections import deque
def solve(N: int, a: "List[int]", b: "List[int]"):
h = [[] for _ in range(N+1)]
edges = [[-1]*(N+1) for _ in range(N+1)]
## 全てのNodeは親は一つだけ
for i in range(N-1):
h[a[i]].append((b[i],i))
h[b[i]].append((a[i]... | #!/usr/bin/env python3
import sys
from collections import deque
def solve(N: int, a: "List[int]", b: "List[int]"):
h = [[] for _ in range(N+1)]
edges = [[-1]*(N+1) for _ in range(N+1)]
## 全てのNodeは親は一つだけ
for i in range(N-1):
h[a[i]].append((b[i],i))
h[b[i]].append((a[i]... | p02850 |
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
N = int(eval(input()))
count = [[] for _ in range(N)]
inputs = []
for _ in range(N - 1):
a, b = list(map(int, input().split()))
count[a - 1].append(b - 1)
count[b - 1].append(a - 1)
inputs.append(sorted([a - 1, b - 1])... | import sys
from collections import deque, OrderedDict
sys.setrecursionlimit(10 ** 7)
N = int(eval(input()))
count = [[] for _ in range(N)]
inputs = OrderedDict()
for _ in range(N - 1):
a, b = list(map(int, input().split()))
count[a - 1].append(b - 1)
count[b - 1].append(a - 1)
inputs["-".j... | p02850 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
COLORS = {(0, 1):0}
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
COLORS[(a, b)] = 0
PREV = {... | import sys
input = sys.stdin.readline
n = int(eval(input()))
GRAPH = {i:[] for i in range(1, n + 1)}
EDGES = []
for _ in range(n - 1):
a, b = list(map(int, input().split()))
GRAPH[a].append(b)
GRAPH[b].append(a)
EDGES.append((a, b))
PREV = {1:0}
Q = [1]
while Q:
now = Q.pop(0)
... | p02850 |
#キューとdictionaryを利用したBFS
from collections import deque
n = int(eval(input()))
ab = [list(map(int,input().split())) for i in range(n-1)]
ver = [[] for i in range(n)]
for i in range(n-1):
a,b = ab[i][0],ab[i][1]
ver[a-1].append(b-1)
ver[b-1].append(a-1)
#print(ver)
color = [dict() for i i... | #d3と同一解法
n=int(eval(input()))
import sys
#再帰関数の再帰回数を変更
sys.setrecursionlimit(10**6)
s=[[] for _ in range(n)]
for i in range(n-1):
a,b=list(map(int,input().split()))
s[a-1].append((b-1,i))
s[b-1].append((a-1,i))
l=[0]*(n-1)
def dfs(node,pre_col,par):
col=1
for nei,i in s[node]:
... | p02850 |
#d3と同一解法
n=int(eval(input()))
import sys
#再帰関数の再帰回数を変更
sys.setrecursionlimit(10**6)
s=[[] for _ in range(n)]
for i in range(n-1):
a,b=list(map(int,input().split()))
s[a-1].append((b-1,i))
s[b-1].append((a-1,i))
l=[0]*(n-1)
def dfs(node,pre_col,par):
col=1
for nei,i in s[node]:
... | import sys
sys.setrecursionlimit(500000)
N = int(eval(input()))
E = [[] for _ in range(N+1)]
for i in range(N-1):
a, b = list(map(int, input().split()))
E[a].append((b, i))
E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
Ans = [-1] * (N-1)
def dfs(v=1, p=0, p_col=-1):
col = 1
fo... | p02850 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#impor... | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#impor... | p02850 |
from collections import deque
def solve(string):
n, *ab = list(map(int, string.split()))
next_ = [dict([]) for _ in range(n + 1)]
queue = deque([1])
for a, b in zip(*[iter(ab)] * 2):
next_[a][b] = 0
next_[b][a] = 0
while len(queue) > 0:
c = queue.popleft()
... | from collections import deque
def solve(string):
n, *ab = list(map(int, string.split()))
e = [[] for _ in range(n + 1)]
q = deque([1])
c = [0] * (n + 1)
for a, b in zip(*[iter(ab)] * 2):
e[a].append(b)
while q:
s = q.popleft()
d = 0
for t in e[s]:
... | p02850 |
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
graph[i - 1].append(j - 1)
graph[j - 1].append(i - 1)
tree[i - 1].append((n, j - 1))
K... | from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
tree[i - 1].append((n, j - 1))
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)
while len(q) > 0:
# u: node number, c: color
... | p02850 |
from collections import defaultdict
N = int(input())
tree = [[] for i in range(N)] # 入力で与えられる木: [[to, 辺のindex],]
degrees = defaultdict(int) # 各頂点の次数を記録
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
tree[a].append([b, i])
tree[b].append([a, i])
degrees[a] +=... | N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
# 辺のindexを持っておく
T[a].append([b, i])
T[b].append([a, i])
stack = [[0, 0]] # [次の頂点番号, 親に続く辺の色]
visited = [0] * N
colors = [0] * (N - 1)
while stack:
n, parent_... | p02850 |
import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for i in range(N-1):
a, b = list(map(int, input().split()))
G[a-1].append((b-1, i))
G[b-1].append((a-1, i))
V = [[-1, -1] for _ in range(N)] # 頂点の[親, 親への辺の色]
a... | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for i in range(N-1):
a, b = list(map(int, input().split()))
G[a-1].append((b-1, i))
G[b-1].append((a-1, i))
V = [[-1, -1] for _ in range(N)] # 頂点の[親, 親への辺の色]
a... | p02850 |
from operator import mul
from functools import reduce
# from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(... | from operator import mul
from functools import reduce
# from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(... | p02850 |
from collections import deque
from copy import deepcopy
N=int(eval(input()))
a=[0]*(N-1)
b=[0]*(N-1)
c=[set() for _ in range(N)]
d=[set() for _ in range(N)] # 隣接リスト
e=[-1 for _ in range(N)] #訪問ずみかどうか
g=[[ 0 for _ in range(N)] for _ in range(N)]
for i in range(N-1):
a[i],b[i] = list(map(int,input().spl... | from collections import deque
from copy import deepcopy
N=int(eval(input()))
a=[0]*(N-1)
b=[0]*(N-1)
c=[set() for _ in range(N)]
d=[set() for _ in range(N)] # 隣接リスト
e=[-1 for _ in range(N)] #訪問ずみかどうか
di=dict()
for i in range(N-1):
a[i],b[i] = list(map(int,input().split()))
d[a[i]-1].add(b[i]-1)
... | p02850 |
from collections import deque
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n-1)]
tree=[[]for _ in range(n)]
for a,b in l:
a-=1
b-=1
tree[a].append(b)
tree[b].append(b)
ans_num=0
for i in tree:
ans_num=max(ans_num,len(i))
dq=deque()
dq.append((0,0))
seen=set()
... | from collections import deque
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n=int(eval(input()))
l=[list(nii()) for i in range(n-1)]
tree=[[]for _ in range(n)]
for a,b in l:
a-=1
b-=1
tree[a].append(b)
tree[b].append(b)
ans_num=0
for i in tree:
ans_num=max(ans_num... | p02850 |
n=int(eval(input()))
ab=[]
p=[-1 for i in range(n+1)]
edge=[[0 for i in range(n+1)] for j in range(n+1)]
G=[[] for i in range(n+1)]
used=[0 for i in range(n+1)]
for i in range(n-1):
ab.append(list(map(int,input().split())))
G[ab[i][0]].append(ab[i][1])
G[ab[i][1]].append(ab[i][0])
max_n=0
for... | n=int(eval(input()))
ab=[]
p=[-1 for i in range(n+1)]
edge={}
G=[[] for i in range(n+1)]
used=[0 for i in range(n+1)]
for i in range(n-1):
ab.append(list(map(int,input().split())))
G[ab[i][0]].append(ab[i][1])
G[ab[i][1]].append(ab[i][0])
max_n=0
for i in range(n+1):
tmp=len(G[i])
i... | p02850 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.