s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s222666787 | p03804 | u270681687 | 1546430393 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 380 | n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
for j in range(n-m)+1:
flag = 0
for k in range(m):
for l in range(m):
if a[i + k][j + l] != b[k][l]:
flag = 1
if flag == 0:
print('Yes')
exit()
print('No')
|
s947098894 | p03804 | u371467115 | 1546001208 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 206 | N,M=map(int,input().strip().split(" "))
a=[input() for i in range(N)
b=[input() for i in range(M)]
N=0
if b[i] in a[i]:
N+=1
if(N==M):
print("Yes")
else:
print("No")
#コピペです。
|
s424809420 | p03804 | u853900545 | 1545084271 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 348 | n,m = map(int,input().split())
a = []
b = []
for i in range(n):
a.append(input())
for i in range(m):
b.append(input())
i = 0
k = 0
ans = 'No'
for k in range(n-m):
while i + m <= n:
if a[k][i:i+m:] == b[k]:
for j in range(m):
if all()
ans = 'Yes'
i += 1
print('No') |
s583462687 | p03804 | u026155812 | 1544249662 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 518 | n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]
B = [[int(i) for i in input().split()] for j in range(m)]
a = 0
for i in range(n-m+1):
for j in range(n-m+1):
if A[0][0] == B[i][j]:
for k in range(m):
for l in range(m):
if A[k][l] != B[i+k][j+l]:
break
else:
a += 1
continue
break
if a != 0:
print(Yes)
else:
print(No) |
s788793387 | p03804 | u371763408 | 1544132731 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 378 | n,m=map(int,input().split())
A=[input() for i in range(n)]
B=[input() for i in range(m)]
for i in range(n):
for j in range(n):
k=j+m
if k <= n:
if A[i][j:k]== B[0]:
o=1
for l in range(i+1,i+m):
if A[l][j:k]!=B[o]:
break
else:
o+=1
if o==m:
print('Yes')
exit()
print('No')
|
s980783965 | p03804 | u386819480 | 1541127598 | Python | Python (3.4.3) | py | Runtime Error | 151 | 12472 | 349 | ## ABC 054 b
import sys
import numpy as np
n,m = (int(_) for _ in input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
aa = np.array(a)
bb = np.array(b)
for i in range(n-m+1):
for j in range(n-m+1):
if (bb[:, :] == aa[i:i+m, j:j+m]):
print('Yes')
sys.exit(0)
print('No') |
s250237858 | p03804 | u386819480 | 1541004312 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 692 | ## ABC 054 B
import sys
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
if(n == m and a == b):
print('Yes')
sys.exit(0)
elif(m == 1):
for i in range(n):
if(b[0] in a[i]):
print('Yes')
sys.exit(0)
print('No')
sys.exit(0)
for k in range(n-m):
idx = []
for j in range(n-m):
if (a[k][j:j + m] == b[k]):
idx.append(j)
continue
for id in idx:
for i in range(k,m):
if(a[i][id:id+m] == b[i]):
continue
else:
print('No')
sys.exit(0)
print('Yes')
sys.exit(0) |
s850259764 | p03804 | u595353654 | 1539537031 | Python | Python (3.4.3) | py | Runtime Error | 148 | 12408 | 302 | # -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
stdin = open("sample.txt")
n,m = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for i in range(n):
s = stdin.readline().rstrip()
A.append(s)
B = []
for i in range(m):
s = stdin.readline().rstrip()
B.append(s) |
s097273242 | p03804 | u099918199 | 1538108821 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 565 | phase = 0
if list_a != list_b:
for i in range(0, n-m):
for j in range(0, n-m):
for k in range(0,m):
if list_a[i+k][j:j+m] == list_b[k]:
if k != m-1:
continue
else:
pass
else:
break
phase = 1
print("Yes")
break
if phase == 1:
break
if phase == 1:
break
else:
print("No")
else:
print("Yes")
|
s634270622 | p03804 | u474270503 | 1536438368 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 253 | N,M=map(int, input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for i in range(N-M+1):
for j in range(N-M+1):
t=[k[j:j+m] for k in a[i:i+m]]
if t==B:
print('Yes')
exit()
print('No')
|
s405652405 | p03804 | u474270503 | 1536438342 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 253 | N,M=map(int, input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for i in range(N-M+1):
for j in range(N-M+1):
t=[k[j:j*m] for k in a[i:i+m]]
if t==B:
print('Yes')
exit()
print('No')
|
s093275757 | p03804 | u474270503 | 1536437464 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 248 | N,M=map(int, input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for i in range(N):
if B[0] in A[i]:
if all(B[j] in A[i+j] for j in range(1,min(M,N-i)):
print('Yes')
exit(0)
print('No')
|
s192114300 | p03804 | u474270503 | 1536437340 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 240 | N,M=map(int, input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for i in range(N):
if B[0] in A[i]:
if all(B[j] in A[i+j] for j in range(1,M)):
print('Yes')
exit(0)
print('No')
|
s094703278 | p03804 | u017810624 | 1536430240 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 304 | n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
for q in range(n-m+1):
if b[0]==a[p][q:q+m]:
for r in range(1,m):
if b[r]!=a[p+r][q:q+m]:break
c=1
break
if c==0:print('No')
else:print('Yes') |
s770331623 | p03804 | u017810624 | 1536426303 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 314 | n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
for q in range(n-m+1):
if b[0]==a[p][q:q+m]:
for r in range(n-m+1):
if b[r]!=a[p+r][q-m+1:q]:pass
else:break
c=1
if c==1:print('Yes')
else:print('No') |
s140342026 | p03804 | u362560965 | 1535165374 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 443 | N, M = (int(i) for i in input().split())
A = []
B = []
for i in range(N):
A.append(input())
for i in range(M):
B.append(input())
for i in range(N-M+1):
if B[0] in A[i]:
pos = A[i].find(B[j])
flag = 0
for j in range(M):
if A[i+j][pos:pos+M] == B[j]:
pass
else:
flag = -1
break
if flag = 0:
print("Yes")
print("No") |
s260405479 | p03804 | u690536347 | 1533230385 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 337 | def f():
n,m=map(int,input().split())
o=[input() for _ in range(n)]
p=[input() for _ in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(i,n-m+1):
for l in range(j,n-m+1):
if p[k-i][l-j]!=o[k][l]:
return False
return True
if f():
print("Yes")
else:
print("No") |
s112525938 | p03804 | u690536347 | 1533230328 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 337 | def f():
n,m=map(int,input().split())
o=[input() for _ in range(n)]
p=[input() for _ in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(i,n-m+1):
for l in range(j,n-m+1):
if p[k-i][l-i]!=o[k][l]:
return False
return True
if f():
print("Yes")
else:
print("No") |
s859658775 | p03804 | u690536347 | 1533229942 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 333 | def f():
n,m=map(int,input().split())
o=[input() for _ in range(n)]
p=[input() for _ in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(i,n-1):
for l in range(j,n-1):
if p[k-i][l-i]!=o[k][l]:
return False
return True
if f():
print("Yes")
else:
print("No") |
s870817189 | p03804 | u612721349 | 1532092384 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 301 | n, m = map(int, input().split())
np = [input() for _ in range(n)]
mp = [input() for _ in range(m)]
for i in range(n-m-1):
for j in range(n-m-1):
f = True
for k in range(m):
if np[i+k][j:j+m] != mp[i+k]:
f = False
if f:
print("Yes")
exit(0)
else:
print("No") |
s435100232 | p03804 | u612721349 | 1532092270 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 297 | n, m = map(int, input().split())
np = [input() for _ in range(n)]
mp = [input() for _ in range(m)]
for i in range(n-m):
for j in range(n-m):
f = True
for k in range(m):
if np[i+k][j:j+m] != mp[i+k]:
f = False
if f:
print("Yes")
exit(0)
else:
print("No") |
s366631930 | p03804 | u140251125 | 1532013460 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 515 | # input
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(N - M + 1):
for j in range(N - M + 1):
for k in range(M):
for l in range(M):
if B[k][l] == A[i + k][j + l]:
ans += 1
else:
break
if ans == M * 2:
print("Yes")
exit()
else:
ans = 0
break
print('No') |
s392490048 | p03804 | u820351940 | 1530994154 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 263 | n, m = map(int, input().split())
img = [input() for i in range(n)]
template = [input() for i in range(m)]
for i in range(n - m + 1):
if len({v.index(t) for v, t in zip(img[i:i + m], template)}) == 1:
print("Yes")
break
else:
print("No")
|
s910926431 | p03804 | u333139319 | 1530283742 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 460 | [n,m]=[int(i) for i in input().split()]
a=[]
b=""
c=[]
d=""
e=1
#a箱,c箱にそれぞれの画像を用意
for i in range(n):
b=b+str(input().split())
a.append(b)
for i in range(m):
d=d+str(input().split())
c.append(d)
print(c)
print(d)
#照合
for i in range(n):
for j in range(m):
f=c[j].find(a[i])
if f!=-1:
for k in range(m):
e=e*(a[f:f+m]!=c[f:f+m])
if e==0:
print("Yes")
else:
print("No")
|
s379012168 | p03804 | u459283268 | 1528585492 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 566 | n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
exits = False
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(n):
match = False
if a[i][k: k+m] == b[j] and not exits:
for l in range(1, m):
if a[i+l][k: k+m] == b[l]:
match = True
else:
match = False
break
if match:
exits = True
print('Yes' if exits else 'No')
|
s040760174 | p03804 | u459283268 | 1528585422 | Python | Python (3.4.3) | py | Runtime Error | 54 | 3064 | 558 | n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
exits = False
for i in range(n):
for j in range(m):
for k in range(n):
match = False
if a[i][k: k+m] == b[j] and not exits:
for l in range(1, m):
if a[i+l][k: k+m] == b[l]:
match = True
else:
match = False
break
if match:
exits = True
print('Yes' if exits else 'No')
|
s456910412 | p03804 | u459283268 | 1528585349 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 558 | n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
exits = False
for i in range(n):
for j in range(n):
for k in range(n):
match = False
if a[i][k: k+m] == b[j] and not exits:
for l in range(1, m):
if a[i+l][k: k+m] == b[l]:
match = True
else:
match = False
break
if match:
exits = True
print('Yes' if exits else 'No')
|
s941001942 | p03804 | u459283268 | 1528585192 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 564 | n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
exits = False
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(n):
match = False
if a[i][k: k+m] == b[j] and not exits:
for l in range(1, m):
if a[l][k: k+m] == b[l]:
match = True
else:
match = False
break
if match:
exits = True
print('Yes' if exits else 'No')
|
s983733132 | p03804 | u214617707 | 1527433652 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 601 | n, m = map(int, input().split())
T1 = [[] for i in range(n)]
T2 = [[] for i in range(m)]
for i in range(n):
a = list(input())
T1[i] = a
for i in range(m):
a = list(input())
T2[i] = a
flag = False
for i in range(n - m + 1):
for j in range(n - m + 1):
if T1[i][j: j + m] == T2[0]:
k = i
l = 0
while k < n - m + 1:
if T1[k][j:j + m] != T2[l]:
break
k += 1
l += 1
if l == m:
flag = True
if flag:
print("Yes")
else:
print("No") |
s900416461 | p03804 | u214617707 | 1527433532 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 597 | n, m = map(int, input().split())
T1 = [[] for i in range(n)]
T2 = [[] for i in range(m)]
for i in range(n):
a = list(input())
T1[i] = a
for i in range(m):
a = list(input())
T2[i] = a
flag = False
for i in range(n - m):
for j in range(n - m):
if T1[i][j: j + m] == T2[0]:
k = i
l = 0
while k < n - m + 1:
if T1[k][j:j + m] != T2[l]:
break
k += 1
l += 1
if k == i + m:
flag = True
if flag:
print("Yes")
else:
print("No") |
s700498340 | p03804 | u040380068 | 1524597882 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2568 | 398 | def judge(a, b, y, x, m):
for i in range(0, m):
for j in range(0, m):
if a[y+i][x+j] != b[y][x]: return False
return True
N, M = map(int, raw_input().split())
A = []
B = []
for i in range(0, N):
A.append(raw_input())
for i in range(0, M):
B.append(raw_input())
ans = 'No'
for i in range(0, N-M+1):
for j in range(0, N-M+1):
if judge(A, B, i, j, M):
ans = 'Yes'
break
print ans
|
s892027948 | p03804 | u040380068 | 1524597786 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 402 | def judge(a, b, y, x, m):
for i in range(0, m):
for j in range(0, m):
if a[y+i][x+j] != b[y+i][x+j]: return False
return True
N, M = map(int, raw_input().split())
A = []
B = []
for i in range(0, N):
A.append(raw_input())
for i in range(0, M):
B.append(raw_input())
ans = 'No'
for i in range(0, N-M+1):
for j in range(0, N-M+1):
if judge(A, B, i, j, M):
ans = 'Yes'
break
print ans
|
s677065292 | p03804 | u803647747 | 1524427932 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 646 | N, M = map(int, input().split())
A_list = []
B_list = []
for _ in range(N):
A_list.append(list(input()))
for _ in range(M):
B_list.append(list(input()))
match_list =[]
for i in range(N-M+1):
for j in range(N-M+1):
if B_list[0] == A_list[i][j:(j+M)]:
match_list.append([i, j])
else:
pass
whole_flag = 0
for k in match_list:
flag =0
for l in range(M):
if A_list[k[0]+l][k[1]:k[1]+M] ==B_list[k[0]+l]:
flag += 1
else:
break
if flag == M:
print("Yes")
whole_flag += 1
if whole_flag == 0:
print("No") |
s825857234 | p03804 | u803647747 | 1524427600 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 634 | N, M = map(int, input().split())
A_list = []
B_list = []
for _ in range(N):
A_list.append(list(input()))
for _ in range(M):
B_list.append(list(input()))
match_list =[]
for i in range(N-M+1):
for j in range(N-M+1):
if B_list[0] == A_list[i][j:(j+M)]:
match_list.append([i, j])
else:
pass
flag =0
for k in match_list:
flag =0
for l in range(M):
if A_list[k[0]+l][k[1]:k[1]+M] ==B_list[k[0]+l]:
flag += 1
else:
break
if flag == M:
print("Yes")
break
if flag == M:
print("Yes")
break |
s144589650 | p03804 | u803647747 | 1524427362 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 658 | N, M = map(int, input().split())
A_list = []
B_list = []
for _ in range(N):
A_list.append(list(input()))
for _ in range(M):
B_list.append(list(input()))
match_list =[]
for i in range(N-M+1):
for j in range(N-M+1):
if B_list[0] == A_list[i][j:(j+M)]:
match_list.append([i, j])
else:
pass
flag =0
for k in match_list:
flag =0
for l in range(M):
print(A_list[k[0]+l][k[1]:k[1]+M])
print(B_list[k[0]+l])
if A_list[k[0]+l][k[1]:k[1]+M] ==B_list[k[0]+l]:
flag += 1
else:
break
if flag == M:
print("Yes")
break |
s436250357 | p03804 | u557171945 | 1522792243 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38640 | 646 | n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<=n-m:
if b[0] in a[i]:
start.append(a[i].index(b[0]))
j += 1
for k in range(1,m):
if b[k] in a[i+j]:
start.append(a[i+j].index(b[k]))
j += 1
if not start[0] == start[j-1]:
start.clear()
j = 0
break
else:
start.clear()
j = 0
break
if len(start)==m:
break
i += 1
print('Yes' if len(start)>0 else 'No')
|
s589668578 | p03804 | u557171945 | 1522791737 | Python | PyPy3 (2.4.0) | py | Runtime Error | 170 | 38640 | 634 | n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<=n-m:
if b[0] in a[i]:
start.append(a[i].index(b[0]))
j += 1
for k in range(1,m):
if b[k] in a[i+j]:
start.append(a[i+j].index(b[k]))
j += 1
else:
start.clear()
j = 0
break
if not start[0] == start[j-1]:
start.clear()
j = 0
break
if len(start)==m:
break
i += 1
print('Yes' if len(start)>0 else 'No')
|
s267372767 | p03804 | u557171945 | 1522769497 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38640 | 598 | n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
i,j = 0,0
start = []
while i<n-m:
if b[0] in a[i]:
start.append(a[i].index(b[0]))
j += 1
for k in range(1,m):
if b[k] in a[i+j]:
start.append(a[i+j].index(b[k]))
j += 1
else:
start.clear()
j = 0
break
if (not start[0] == start[j-1]):
start.clear()
j = 0
break
i += 1
print('Yes' if len(start)>0 else 'No') |
s992920173 | p03804 | u030726788 | 1519272940 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 460 | import sys
N,M=map(int,input().split())
Ai=[]
Bi=[]
for i in range(N):
Ai.append(input())
for i in range(M):
Bi.append(input())
roop=N-M+1
for i in range(roop):
for j in range(roop):
#print("")
flag=1
for k in range(roop):
#print(Ai[i+k][j:j+M])
if(Ai[i+k][j:j+M]!=Bi[k]):
flag=0
break;
if(flag==1):
print("Yes")
sys.exit()
print("No")
|
s721520865 | p03804 | u103539599 | 1517112584 | Python | Python (3.4.3) | py | Runtime Error | 377 | 18604 | 366 | import numpy as np
N,M=map(int, input().split())
A=[]
for i in range(N):
a=list(input())
A.append(a)
B=[]
for i in range(M):
b=list(input())
B.append(b)
An=np.array(A)
Bn=np.array(B)
t=0
for i in range(N):
for j in range(N):
if Bn in An[i:i+M,j:j+M]:
t=1
break
if t==1:
print("Yes")
else:
print("No")
|
s737834903 | p03804 | u010110540 | 1506708142 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 471 | N = int(input())
M = int(input())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(N-M+1):
for j in range(N-M+1):
flag = True
for k in range(M):
for l in range(M):
if A[i+k][j+l] != B[k][l]:
flag = False
break
if not flag:
break
if flag:
print('Yes')
exit()
print('No') |
s076571041 | p03804 | u665415433 | 1506565457 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 661 | def solve(n, m, NUM):
for i in range(len(m)):
if n[NUM + i] is not m[i]:
return -1
return 1
N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
for n in n_pic:
if -1 is not n.find(m_pic[0]):
print('Yes')
exit()
print('No')
exit()
for n in range(len(n_pic)):
for n_len in range(N - M + 1):
while -1 is not solve(n_pic[n+num], m_pic[num], n_len):
num += 1
print(num)
if num is M:
print('Yes')
exit()
num = 0
print('No')
|
s692592268 | p03804 | u665415433 | 1506564612 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3064 | 607 | def solve(n, m, NUM):
for i in range(len(m)):
if n[NUM + i] is not m[i]:
return -1
return 1
N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
for n in n_pic:
if -1 is not n.find(m_pic[0]):
print('Yes')
exit()
print('No')
exit()
for n in n_pic:
for n_len in range(N - M + 1):
while -1 is not solve(n, m_pic[num], n_len):
num += 1
if num is M - 1:
print('Yes')
exit()
num = 0
print('No')
|
s060513174 | p03804 | u075012704 | 1492049602 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 389 | N , M = map(int , input().split())
A = []
B = []
flg=True
for i in range(N):
A.append([j for j in input()])
for i in range(M):
B.append([j for j in input()])
for i in range((N-M-1)*(N-M-1)):
for j in range(M):
for l in range(M):
if B[j][l] != A[j+i][l+i]:
flg = False
break
if flg:
print("Yes")
else:
print("No") |
s285931094 | p03804 | u107077660 | 1491342622 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3064 | 371 |
N, M = map(int, input().split())
A = []
for i in range(N):
A.append(input())
B = []
for i in range(M):
B.append(input())
t = 0
for i in range(N):
for j in range(N-M):
t = 0
for k in range(M):
if t:
break
for l in range(M):
if A[i+k][j+l] != B[k][l]:
t = 1
break
else:
if A[i+k][j+l] == B[k][l]:
print("Yes")
exit()
print("No") |
s152276666 | p03804 | u622568141 | 1489554886 | Python | Python (3.4.3) | py | Runtime Error | 282 | 20656 | 661 | # -*- coding: utf-8 -*-
import sys
import math
import numpy as np
def main():
# 入力処理
# M = int(input())
N, M = map(int, input().split())
sA = ''.join([input() for i in range(N)])
sB = ''.join([input() for i in range(M)])
A = np.array([s for s in sA]).reshape(N,N)
B = np.array([s for s in sB]).reshape(M,M)
# アルゴリズム本体
result = np.zeros((N-M,N-M), dtype=bool)
for i in range(N-M+1):
for j in range(N-M+1):
result[i,j] = (A[i:i+M, j:j+M] == B).all()
# 出力
if result.any():
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
s348580005 | p03804 | u466826467 | 1489125296 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3316 | 794 | import re
first_line = input().split()
n = int(first_line[0])
m = int(first_line[1])
n_list = []
for i in range(n):
n_list.append(input())
m_list = []
for i in range(m):
m_list.append(input())
if m == n:
if n_list == m_list:
print("Yes")
else:
print("No")
else:
match_flg = False
for i in range(0, n - m):
matchOb = re.match(m_list[0], n_list[i])
if matchOb:
start_pos = matchOb.start()
end_pos = matchOb.end()
for j in range(0, m):
if n_list[i + j][start_pos:end_pos] == m_list[j] and j == m - 1:
match_flg = True
elif n_list[i + j][start_pos:end_pos] != m_list[j]:
break
if match_flg:
print("Yes")
else:
print("No")
|
s121067134 | p03804 | u848877025 | 1488686694 | Python | Python (2.7.6) | py | Runtime Error | 12 | 2692 | 805 | def main():
nm = map(int, raw_input().split())
A = []
B = []
flag = False
for i in range(nm[0]):
A.append(raw_input())
for i in range(nm[1]):
B.append(raw_input())
for i in range(nm[0]):
for j in range(nm[0]):
if j + nm[1] <= nm[0]:
for k in range(nm[1]):
for l in range(nm[1]):
if(A[i+k][j+l] == B[k][l]):
flag = True
else:
flag = False
break
if flag == False:
break
if flag:
break
if flag:
break
if flag:
return "Yes"
else:
return "No"
print main() |
s673294446 | p03804 | u848877025 | 1488686648 | Python | Python (2.7.6) | py | Runtime Error | 12 | 2696 | 805 | def main():
nm = map(int, raw_input().split())
A = []
B = []
flag = False
for i in range(nm[0]):
A.append(raw_input())
for i in range(nm[1]):
B.append(raw_input())
for i in range(nm[0]):
for j in range(nm[0]):
if j + nm[1] <= nm[0]:
for k in range(nm[1]):
for l in range(nm[1]):
if(A[i+k][j+l] == B[k][l]):
flag = True
else:
flag = False
break
if flag == False:
break
if flag:
break
if flag:
break
if flag:
return "yes"
else:
return "no"
print main() |
s774181104 | p03804 | u848877025 | 1488686589 | Python | Python (2.7.6) | py | Runtime Error | 12 | 2696 | 805 | def main():
nm = map(int, raw_input().split())
A = []
B = []
flag = False
for i in range(nm[0]):
A.append(raw_input())
for i in range(nm[1]):
B.append(raw_input())
for i in range(nm[0]):
for j in range(nm[0]):
if j + nm[1] <= nm[0]:
for k in range(nm[1]):
for l in range(nm[1]):
if(A[i+k][j+l] == B[k][l]):
flag = True
else:
flag = False
break
if flag == False:
break
if flag:
break
if flag:
break
if flag:
return "yes"
else:
return "no"
print main() |
s187061516 | p03804 | u916127336 | 1488093016 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2568 | 308 | N, M = map(int, raw_input().split())
imgA = []
imgB = []
for i in range(N):
imgA += raw_input().split()
for i in range(M):
imgB += raw_input().split()
for i in range(N - M):
for j in range(M):
for k in range(M):
if (imgA[(i + k) * N + j] != imgB[k * M + j]): return 'No'
return 'Yes'
|
s920278968 | p03804 | u805887876 | 1487798561 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 327 | for i in xrange(0,n-m+1):
for j in xrange(0, n-m+1):
flag = True
for x in xrange(0, m):
for y in xrange(0, m):
if mp[x][y] != np[i+x][j+y]:
flag = False
break
if flag == False:
break
if flag:
print "Yes"
break
if flag: break
if flag==False: print "No" |
s846546076 | p03804 | u805887876 | 1487798385 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 440 | n,m = map(int, raw_input().split())
np=[]
mp=[]
for i in xrange(0, n):
np.append(raw_input())
for i in xrange(0, m):
mp.append(raw_input())
for i in xrange(0,n-m+1):
for j in xrange(0, n-m+1):
flag = True
for x in xrange(0, m):
for y in xrange(0, m):
if mp[x][y] != np[i+x][j+y]:
flag = False
break
if flag == False:
break
if flag:
print "Yes"
return
print "No" |
s357992703 | p03804 | u805887876 | 1487797747 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 376 | np=[]
mp=[]
for i in xrange(0, n):
np.append(raw_input())
for i in xrange(0, m):
mp.append(raw_input())
for i in xrange(0,n-m):
for j in xrange(0, n-m):
flag = True
for l in xrange(0, m):
for m in xrange(0, n):
if mp[l][m] != np[i][j]:
flag = False
break
if !flag:
break
if flag:
print "Yes"
else:
print "No" |
s104330711 | p03804 | u098572984 | 1487127977 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 499 | N, M = input().split()
A=[]
for i in range(0,N):
A.append(input())
B=[]
for j in range(0,M):
B.append(input())
ref_tuple = zip(range(0,N-M+1),range(0,N-M+1))
t=False
for ref_row_a, ref_col_a in ref_tuple:
for row_b, col_b in zip(range(0,M),range(0,M)):
if not A[ref_row_a+row_b][ref_col_a+col_b]==B[row_b][col_b]:
break
if (row_b, col_b)==(M-1,M-1):
t=True
break
if t:
break
if t:
print('Yes')
else:
print('No')
|
s750503407 | p03804 | u249895018 | 1486922608 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 723 | #include <string>
#include <iostream>
using namespace std;
const int nmax = 50;
const int mmax = 50;
char N_sq[nmax][nmax], M_sq[mmax][mmax];
bool judge_match(int x, int y, int M){
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
if(N_sq[y+i][x+j] != M_sq[y+i][x+j]) return false;
}
}
return true;
}
int main(void){
int N,M;
cin >> N >> M;
bool exist = false;
for(int y=0;y < N;y++){
for(int x;x < N;x++){
cin >> N_sq[y][x];
}
}
for(int y=0;y < M;y++){
for(int x;x < M;x++){
cin >> M_sq[y][x];
}
}
for(int y=0;y <= N - M;y++){
for(int x=0;x <= N - M;x++){
if(judge_match(x, y, M)) exist=true;
}
}
if(exist)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} |
s201086430 | p03804 | u889075007 | 1486881786 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 631 | # -*- coding: utf-8 -*-
# スペース区切りの整数の入力
checker = True
n, m = map(int, raw_input().split())
N = []
M = []
counter = 0
ans = "No"
flag = 0
while checker:
tmp = raw_input()
if counter < n:
N.append(tmp)
else:
M.append(tmp)
counter += 1
if counter == n + m:
break
if M[0].find(N[0]) > -1:
flag = 1
start = M[0].find(N[0]) #開始文字列index
for st in M:
for stm in N:
ch = st.find(stm)
if ch == start:
else:
flag = 0
ans = "Yes" if flag == 1 else "No"
# 出力
print ans |
s593564565 | p03804 | u598167418 | 1486868768 | Python | Python (2.7.6) | py | Runtime Error | 42 | 2696 | 724 | import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
at = list(raw_input())
a[i] = at
for i in range(m):
at = list(raw_input())
b[i] = at
if n == m:
if a == b:
print "Yes"
sys.exit(0)
else:
print "No"
sys.exit(0)
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
for k in range(m):
temp[k] = a[i+k][j:j+m]
if temp == b:
print "Yes"
sys.exit(0)
else:
temp = [[0 for i in range(m)] for j in range(m)]
print "No"
|
s687871371 | p03804 | u106342872 | 1486867311 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 442 | n,m = map(int,input().split())
a = []
for i in range(n):
a.append(str(input()))
b = []
for i in range(m):
b.append(str(input()))
f = [0]*m
count = 0
for j in range(m):
f[j] = a[j].find(b[j])
while -1 in f: f.remove(-1)
if len(f) == 0:
print('No')
else:
flag = 1
for i in range(len(f)):
if (b[f[i]] in a[f[i]]) == False:
flag =0
if flag == 1:
print('Yes')
else:
print('No') |
s646773390 | p03804 | u714779404 | 1486867283 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2696 | 1260 | n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
n_list.append(raw_input())
for x in range(0, m):
m_list.append(raw_input())
def match_first_rows(n_start):
result = (-1,-1)
first_m = m_list[0] # first row
for x in range(n_start, n):
n_row = n_list[x]
if first_m in n_row: # substring matching of first m_row
j = n_row.index(first_m)
return (x, j)
return (-1,-1) #return -1,-1 if none found
# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
nx_start = i
ny_start = j
for x in range(0,m):
n_row_string = n_list[nx_start+x]
n_string = n_row_string[j:j+m] # align window
m_string = m_list[x]
if n_string!=m_string:
return False
return True
def find_m():
found_m = False
counter = 0
while(counter<n and not(found_m)):
i,j = match_first_rows(counter)
if i==-1:
#goes through entirety, not returning things at all
print("No")
found_m = True
# found a potential starting point
else:
result = begin_matching(i,j)
if result:
print("Yes")
found_m = True
else:
#do it again, but one row lower
counter +=1
find_m()
|
s697519693 | p03804 | u713023102 | 1486867179 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2692 | 453 | data = raw_input()
n,m = map(int,data.split(" "))
data = []
for x in range(n):
data.append(raw_input())
temp = []
for x in range(m):
temp.append(raw_input())
for x in range(n):
for y in range(n):
if temp[0] == data[x][y:y+m]:
flag = 1
pos = y
for xx in range(x+1,x+m):
if temp[xx - x] != data[xx][pos:pos+m]:
flag = 0
break
if flag == 1:
print "Yes"
exit(0)
print "No" |
s635198612 | p03804 | u106342872 | 1486867144 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 463 | n,m = map(int,input().split())
a = []
for i in range(n):
a.append(str(input()))
b = []
for i in range(m):
b.append(str(input()))
f = [0]*m
count = 0
for j in range(m):
f[j] = a[j].find(b[j])
while -1 in f: f.remove(-1)
if len(f) == 0:
print('No')
else:
flag = 1
for i in range(len(f)):
if b[f[i]] in a[f[i]]:
pass
else:
flag =0
if flag == 1:
print('Yes')
else:
print('No') |
s646013440 | p03804 | u668253056 | 1486867133 | Python | Python (3.4.3) | py | Runtime Error | 1555 | 16800 | 538 | import numpy as np
import sys
temp = input().split()
N = int(temp[0])
M = int(temp[1])
A = []
B = []
check = False
def change(n):
if(n=='#'):
return True;
return False;
for i in range(N):
temp = input()
A.append(list(map(change, temp)))
for i in range(M):
temp = input()
B.append(list(map(change, temp)))
A = np.array(A)
B = np.array(B)
for i in range(N-M+1):
for j in range(N-M+1):
if (B== A[i:M+j, i:M+j]).all():
check = True
break
if check:
break
if check:
print("Yes")
else:
print("No")
|
s243926733 | p03804 | u553070003 | 1486867076 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3192 | 587 | n, m = map(int, input().split())
A, B = [], []
for i in range(n):
A.append(input())
for i in range(m):
B.append(input())
def is_contain(i, b_pos):
containing = True
for a_i in range(i+1, i+m):
if A[a_i][b_pos:(b_pos+len(B))] != B[a_i]:
containing = False
return containing
if n < m or len(A) < len(B):
print("No")
exit()
for i in range(n - m + 1):
lineA = A[i]
lineB = B[i%m]
lineB_pos = lineA.find(lineB)
if lineB_pos >= 0:
if is_contain(i, lineB_pos):
print("Yes")
exit()
print("No") |
s170732204 | p03804 | u668253056 | 1486867041 | Python | Python (3.4.3) | py | Runtime Error | 282 | 20744 | 474 | import numpy as np
import sys
temp = input().split()
N = int(temp[0])
M = int(temp[1])
A = []
B = []
def change(n):
if(n=='#'):
return True;
return False;
for i in range(N):
temp = input()
A.append(list(map(change, temp)))
for i in range(M):
temp = input()
B.append(list(map(change, temp)))
A = np.array(A)
B = np.array(B)
for i in range(N-M+1):
for j in range(N-M+1):
if (B== A[i:M+j, i:M+j]).all():
print("Yes")
sys.exit()
print("No")
|
s041461362 | p03804 | u714779404 | 1486866817 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 1262 | n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
n_list.append(raw_input())
for x in range(0, m):
m_list.append(raw_input())
def match_first_rows(n_start):
result = (-1,-1)
first_m = m_list[0] # first row
for x in range(n_start, n):
n_row = n_list[x]
if first_m in n_row: # substring matching of first m_row
j = n_row.index(first_m)
return (x, j)
return (-1,-1) #return -1,-1 if none found
# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
nx_start = i
ny_start = j
for x in range(0,m):
n_row_string = n_list[nx_start+x]
n_string = n_row_string[j:j+m] # align window
m_string = m_list[x]
if n_string!=m_string:
return False
return True
def find_m():
found_m = False
counter = 0
while(counter<n and not(found_m)):
i,j = match_first_rows(counter)
if i==-1:
#goes through entirety, not returning things at all
print("No")
found_m = True
# found a potential starting point
else:
result = begin_matching(i,j)
if result:
print("Yes")
found_m = True
else:
#do it again, but one row lower
counter +=1
find_m()
|
s549996123 | p03804 | u668253056 | 1486866684 | Python | Python (3.4.3) | py | Runtime Error | 299 | 12756 | 451 | import numpy as np
import sys
N = int(input())
M = int(input())
A = []
B = []
def change(n):
if(n=='#'):
return True;
return False;
for i in range(N):
temp = input()
A.append(list(map(change, temp)))
for i in range(M):
temp = input()
B.append(list(map(change, temp)))
A = np.array(A)
B = np.array(B)
for i in range(N-M+1):
for j in range(N-M+1):
if (B== A[i:M+j, i:M+j]).all():
print("Yes")
sys.exit()
print("No")
|
s283069002 | p03804 | u102113963 | 1486866548 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 476 | N,M = map(int, input().split())
A = []
B = []
for i in range(N):
A.append(input())
for i in range(M):
B.append(input())
for i in range(N-M):
x = A[i].find(B[0])
if x != -1:
result = True
break
result = False
for j in range(1,M):
if (j >= M or j >= N ):
result = False
break
idx = A[j][x:].find(B[j])
if idx != x:
result = False
break
if result == True:
print("Yes")
else:
print("No") |
s833950404 | p03804 | u102113963 | 1486866419 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 411 | N,M = map(int, input().split())
A = []
B = []
for i in range(N):
A.append(input())
for i in range(M):
B.append(input())
for i in range(N-M):
x = A[i].find(B[0])
if x != -1:
result = True
break
result = False
for j in range(1,M):
idx = A[j][x:].find(B[j])
if idx != x:
result = False
break
if result == True:
print("Yes")
else:
print("No") |
s137378914 | p03804 | u272028993 | 1486865447 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 493 | def check(y,x):
if 0<=y<=n-1 and 0<=x<=n-1:
return True
return False
n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(m):
for j in xrange(m):
cnt=0
for k in range(i,i+m):
for l in xrange(j,j+m):
if check(k,l):
if a[k][l]==b[k][l]:
cnt+=1
if cnt==m*m:
print("Yes")
exit()
print("No")
|
s944746041 | p03805 | u521323621 | 1600990215 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9580 | 381 | import queue
n,m = map(int, input().split())
ma = [[] for i in range(n+1)]
for i in range(n):
a,b = map(int, input().split())
ma[a].append(b)
ma[b].append(a)
ans = 0
def dfs(i):
global ans
if all(reach[1:]):
ans += 1
for j in ma[i]:
if reach[j] == 1:
continue
reach[j] = 1
dfs(j)
reach[j] = 0
reach=[0]*(n+1)
reach[1] = 1
dfs(1)
print(ans) |
s414476205 | p03805 | u682467216 | 1600902495 | Python | PyPy3 (7.3.0) | py | Runtime Error | 88 | 75004 | 1664 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 8)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
return ans
print(dfs(1, 0))
|
s614395127 | p03805 | u682467216 | 1600901928 | Python | PyPy3 (7.3.0) | py | Runtime Error | 84 | 74992 | 1854 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 8)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
if len(graph[now - 1]) > 0:
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s031388351 | p03805 | u682467216 | 1600901763 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9648 | 1814 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 8)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s995240667 | p03805 | u682467216 | 1600901681 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 69044 | 1814 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 9)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s200072422 | p03805 | u682467216 | 1600901661 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 74948 | 1814 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 8)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s563546010 | p03805 | u682467216 | 1600901598 | Python | PyPy3 (7.3.0) | py | Runtime Error | 89 | 74868 | 1815 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 16)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s045431895 | p03805 | u682467216 | 1600901563 | Python | PyPy3 (7.3.0) | py | Runtime Error | 90 | 74772 | 1806 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 7)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b-1)
graph[b - 1].append(a-1)
def dfs(now, depth):
if v[now]:
return 0
if depth == n-1:
return 1
ans = 0
v[now] = True
for node in graph[now]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(0, 0))
|
s522019958 | p03805 | u682467216 | 1600901364 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 75032 | 1814 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 7)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s044719905 | p03805 | u682467216 | 1600901086 | Python | PyPy3 (7.3.0) | py | Runtime Error | 85 | 74900 | 1814 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[now - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s726346477 | p03805 | u682467216 | 1600900760 | Python | PyPy3 (7.3.0) | py | Runtime Error | 97 | 75128 | 1810 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[n - 1]:
return 0
if depth == n-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s213590428 | p03805 | u682467216 | 1600900580 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2208 | 85368 | 1825 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
n, m = LI()
graph = [[] for _ in range(m)]
v = [False for _ in range(n)]
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
def dfs(now, depth):
if v[n - 1]:
return 0
if depth == m-1:
return 1
ans = 0
v[now - 1] = True
for node in graph[now - 1]:
ans += dfs(node, depth+1)
v[now - 1] = False
# ここが大事.上で探索の一つが終わるからリセットしている.
return ans
print(dfs(1, 0))
|
s570101249 | p03805 | u682467216 | 1600900452 | Python | PyPy3 (7.3.0) | py | Runtime Error | 83 | 74808 | 1813 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
def dfs(n, depth):
if v[n - 1]:
return 0
if depth == m-1:
return 1
ans = 0
v[n - 1] = True
for node in graph[n - 1]:
ans += dfs(node, depth+1)
v[n - 1] = False # ここが大事.上で探索の一つが終わるからリセットしている.
return ans
n, m = LI()
graph = [[] for _ in range(m)]
v = [False for _ in range(n)]
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
print(dfs(1, 0))
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
|
s382214926 | p03805 | u682467216 | 1600900128 | Python | PyPy3 (7.3.0) | py | Runtime Error | 83 | 74860 | 1822 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, m = LI()
graph = [[] for _ in range(m)]
v = [False for _ in range(n)]
def dfs(n, depth):
if v[n - 1] == True:
return 0
if depth == m-1:
return 1
ans = 0
v[n - 1] = True
for node in graph[n - 1]:
ans += dfs(node, depth+1)
v[n - 1] = False # ここが大事.上で探索の一つが終わるからリセットしている.
return ans
for i in range(m):
a, b = LI()
graph[a - 1].append(b)
graph[b - 1].append(a)
print(dfs(1, 0))
# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2
|
s536862909 | p03805 | u339199690 | 1600696002 | Python | PyPy3 (7.3.0) | py | Runtime Error | 84 | 68452 | 414 | from itertools import permutations
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N):
a, b = map(int, input().split())
a, b = a - 1, b - 1
G[a].append(b)
G[b].append(a)
res = 0
for P in permutations(range(N), N):
if P[0] != 0:
continue
for i in range(N - 1):
if P[i + 1] not in G[P[i]]:
break
else:
res += 1
print(res)
|
s569519923 | p03805 | u339199690 | 1600695995 | Python | Python (3.8.2) | py | Runtime Error | 36 | 9152 | 414 | from itertools import permutations
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N):
a, b = map(int, input().split())
a, b = a - 1, b - 1
G[a].append(b)
G[b].append(a)
res = 0
for P in permutations(range(N), N):
if P[0] != 0:
continue
for i in range(N - 1):
if P[i + 1] not in G[P[i]]:
break
else:
res += 1
print(res)
|
s473376682 | p03805 | u745561510 | 1600555047 | Python | PyPy3 (7.3.0) | py | Runtime Error | 119 | 74116 | 481 | import itertools
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
pattern = [i for i in range(N)]
ans = 0
for i in itertools.permutations(pattern):
flag = True
now = i[j]
to = i[j+1]
if i[0] != 0:
continue
for j in range(len(i) - 1):
if not to in G[now]:
flag = False
if flag:
ans += 1
print(ans) |
s852504653 | p03805 | u745561510 | 1600555022 | Python | PyPy3 (7.3.0) | py | Runtime Error | 85 | 74708 | 485 | import itertools
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
pattern = [i for i in range(N)]
ans = 0
for i in itertools.permutations(pattern):
flag = True
now = i[j]
next = i[j+1]
if i[0] != 0:
continue
for j in range(len(i) - 1):
if not next in G[now]:
flag = False
if flag:
ans += 1
print(ans) |
s524134344 | p03805 | u806976856 | 1600209808 | Python | PyPy3 (7.3.0) | py | Runtime Error | 102 | 74420 | 360 | n,m=map(int,input().split())
road=[[] for _ in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
road[a].append(b)
road[b].append(a)
dp=[[0]*(n+1) for _ in range(2**n)]
dp[1][1]=1
for i in range(1,2**n):
for j in range(1,n+1):
for k in road[j]:
dp[i+2**(k-1)][k]+=dp[i][j]
print(sum(dp[2**n-1]))
|
s774041025 | p03805 | u637289184 | 1599663753 | Python | PyPy3 (7.3.0) | py | Runtime Error | 94 | 74564 | 408 | import itertools
N, M = map(int, input().split())
p=[[0]*N for i in range(N)]
for i in range(M):
a,b=map(int,input().split())
p[a-1][b-1]=1
p[b-1][a-1]=1
cnt=0
a=[i for i in range(N)]
for i in itertools.permutations(a):
flag=0
if i[0]==0:
for j in range(1,M):
if p[i[j]][i[j-1]]!=1:
flag=1
if flag==0:
cnt+=1
print(cnt)
|
s625726331 | p03805 | u552738814 | 1599623188 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9148 | 861 | N,M = map(int,input.split())
#iから進める場所をリストにして保管
edges = {i:[] for i in range(1,N+1)}
for i in range(M):
a,b = [int(a) for a in input().split()]
edges[a].append(b)
edges[b].append(a)
#深さ優先探索
def dfs(list):
#lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功)
if len(list) == N:
return 1
else:
a = list[-1]
#lstの最後尾(現在地)が次に進める場所をnextとしてリスト化
#nextに以前通った場所が入っていないか確認
next = [n for n in edges[a] if n not in list]
#次に進める場所がなくなったら探索終了(失敗)
if len(next) == 0:
return 0
total = 0
#再帰でさらに探索
for n in next:
total += dfs(list + [n])
return total
ans = dfs([1])
print(ans)
|
s319398602 | p03805 | u552738814 | 1599622913 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9096 | 832 | N,M = map(int,input().split())
edges = {i:[] for i in range(1,M+1)}
for i in range(M):
a,b = map(int,input().split())
edges[a].append(b)
edges[b].append(a)
#深さ優先探索
def dfs(list):
#lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功)
if len(list) == N:
return 1
else:
x = list[-1]
#lstの最後尾(現在地)が次に進める場所をnextとしてリスト化
#nextに以前通った場所が入っていないか確認
next = [n for n in edges[x] if n not in list]
#次に進める場所がなくなったら探索終了(失敗)
if len(next) == 0:
return 0
total = 0
#再帰でさらに探索
for n in next:
total += dfs(list + [n])
return total |
s209328469 | p03805 | u637289184 | 1599620667 | Python | PyPy3 (7.3.0) | py | Runtime Error | 96 | 74616 | 353 | import itertools
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
cnt=0
for l in range(1,N+1):
for i in itertools.combinations(A,l):
a=[0]*N
for j,k in i:
a[j-1]+=1
a[k-1]+=1
if a[0]==1 and a.count(1)==2 and a.count(2)==N-2:
cnt+=1
print(cnt)
|
s679940020 | p03805 | u314825579 | 1598161969 | Python | Python (3.8.2) | py | Runtime Error | 88 | 9096 | 460 | #一度だけ頂点を通る⇒辺の数=頂点-1
import itertools
Mlist=[]
N,M=map(int,input().split(' '))
for i in range(N):
Mlist.append(list(map(int,input().split(" "))))
all_parterns=itertools.permutations(range(M),r=N-1)
#all_parterns=[(0,2,3,5,6,1)]
ans=0
for partern in all_parterns:
x=1
IsOk=True
for i in partern:
a,b=Mlist[i]
if x==a:
x=b
elif x==b:
x=a
else:
IsOk=False
if IsOk:
ans+=1
print(ans) |
s602129097 | p03805 | u200916944 | 1597975372 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9100 | 492 | from itertools import permutations
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
m = [set() for _ in range(1, 9)]
for a, b in AB:
m[a].add(b)
m[b].add(a)
def main():
ans = []
def traverse(n, visits):
visits = visits | set([n])
if len(visits) == N:
ans.append(1)
return
for c in m[n] - visits:
traverse(c, visits)
traverse(1, set())
return len(ans)
print(main()) |
s109328626 | p03805 | u106971015 | 1597805754 | Python | Python (3.8.2) | py | Runtime Error | 29 | 9188 | 528 | N,M = map(int,input().split())
line = [[] for _ in range(M)]
for _ in range(N):
a,b = map(int,input().split())
line[a-1].append(b-1)
line[b-1].append(a-1)
check = [False] * N
def dfs(now):
global cnt
global ans
if cnt == N:
ans += 1
else:
for i in line[now]:
if check[i] == False:
check[i] = True
cnt += 1
dfs(i)
check[i] = False
cnt -= 1
check[0] = True
cnt = 1
ans = 0
dfs(0)
print(ans) |
s269078733 | p03805 | u106971015 | 1597805537 | Python | Python (3.8.2) | py | Runtime Error | 33 | 9140 | 528 | N,M = map(int,input().split())
line = [[] for _ in range(M)]
for _ in range(M):
a,b = map(int,input().split())
line[a-1].append(b-1)
line[b-1].append(a-1)
check = [False] * N
def dfs(now):
global cnt
global ans
if cnt == N:
ans += 1
else:
for i in line[now]:
if check[i] == False:
check[i] = True
cnt += 1
dfs(i)
check[i] = False
cnt -= 1
check[0] = True
cnt = 1
ans = 0
dfs(0)
print(ans) |
s796149391 | p03805 | u648881683 | 1597606963 | Python | Python (3.8.2) | py | Runtime Error | 824 | 502068 | 965 | import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N, M = LI()
G = [[] for _ in range(N)]
for _ in range(M):
a, b = LI_()
G[a].append(b)
G[b].append(a)
ans = [0]
visited = [False] * N
def dfs(depth, c):
visited[c] = True
if depth == N - 1:
ans[0] += 1
else:
for n in G[c]:
if not visited[n]:
dfs(n, depth + 1)
visited[n] = False
dfs(0, 0)
print(ans[0])
if __name__ == '__main__':
resolve()
|
s845322609 | p03805 | u035210736 | 1597366662 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9152 | 355 | n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
c = [i for i in range(2, n + 1)]
b = []
for x in itertools.permutations(c):
b.append([1] + list(x))
cnt = 0
for x in b:
exist = True
for i in range(n-1):
if not sorted(x[i:i+2]) in a:
exist = False
break
if exist:
cnt += 1
print(cnt) |
s255803966 | p03805 | u338597441 | 1597246733 | Python | Python (3.8.2) | py | Runtime Error | 36 | 9116 | 435 | import itertools as it
n,m=map(int,input().split())
ans=[]
for i in range(n):
a,b=map(int,input().split())
ans.append([a,b])
ans.append([b,a])
a=0
for e in it.permutations(range(n)):
#print(e)
count=1
if e[0]!=0:
break
for i in range(n-1):
if [e[i]+1,e[i+1]+1] in ans:
count*=1
else:
count*=0
break
a+=count
print(a) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.