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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s371660727 | p03805 | u338597441 | 1597245933 | Python | Python (3.8.2) | py | Runtime Error | 35 | 9116 | 440 | 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(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count*=1
else:
count*=0
break
a+=count
print(a) |
s305547396 | p03805 | u338597441 | 1597245760 | Python | Python (3.8.2) | py | Runtime Error | 35 | 9152 | 426 | 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)):
count=0
if e[0]!=0:
break
for i in range(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count*=1
else:
count*=0
break
a+=count
print(a) |
s222403239 | p03805 | u338597441 | 1597245662 | Python | Python (3.8.2) | py | Runtime Error | 55 | 9064 | 407 | 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)):
count=0
if e[0]!=0:
break
for i in range(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count=1
else:
count*=0
a+=count
print(a) |
s211388908 | p03805 | u338597441 | 1597245510 | Python | Python (3.8.2) | py | Runtime Error | 51 | 9104 | 406 | 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)):
count=0
if e[0]!=0:
break
for i in range(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count=1
else:
count=0
a+=count
print(a) |
s038260829 | p03805 | u338597441 | 1597245363 | Python | Python (3.8.2) | py | Runtime Error | 51 | 9068 | 407 | 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])
for e in it.permutations(range(n)):
count,a=0,0
if e[0]!=0:
break
for i in range(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count=1
else:
count=0
a+=count
print(a) |
s577536158 | p03805 | u338597441 | 1597243309 | Python | Python (3.8.2) | py | Runtime Error | 51 | 9144 | 411 | 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])
count,a=0,0
for e in it.permutations(range(n)):
if e[0]!=0:
break
for i in range(len(e)-1):
if [e[i]+1,e[i+1]+1] in ans:
count=1
else:
count=0
a+=count
print(a)
|
s738257957 | p03805 | u958958520 | 1596906527 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9232 | 591 | import sys
sys.setrecursionlimit(10000000)
n,m = map(int,input().split())
graph = [list(input().split(" ")) for i in range(n)]
result=0
def dfs(a, list, graph, result):
if len(list) == n:
result = result + 1
for g in graph:
if g[0] == a and g[1] not in list:
list.append(g[1])
result = dfs(g[1], list, graph, result)
if g[1] == a and g[0] not in list:
list.append(g[0])
result = dfs(g[0], list, graph, result)
return result
for g in graph:
list = []
if g[0] == "1":
list.append(1)
result += dfs("1", list, graph, 0)
print(result)
|
s812201231 | p03805 | u958958520 | 1596906486 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9236 | 589 | import sys
sys.setrecursionlimit(100000)
n,m = map(int,input().split())
graph = [list(input().split(" ")) for i in range(n)]
result=0
def dfs(a, list, graph, result):
if len(list) == n:
result = result + 1
for g in graph:
if g[0] == a and g[1] not in list:
list.append(g[1])
result = dfs(g[1], list, graph, result)
if g[1] == a and g[0] not in list:
list.append(g[0])
result = dfs(g[0], list, graph, result)
return result
for g in graph:
list = []
if g[0] == "1":
list.append(1)
result += dfs("1", list, graph, 0)
print(result)
|
s876791595 | p03805 | u958958520 | 1596906316 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9220 | 573 | import sys
n,m = map(int,input().split())
graph = [list(input().split(" ")) for i in range(n)]
result=0
def dfs(a, list, graph, result):
print(list)
if len(list) == n:
result = result + 1
for g in graph:
if g[0] == a and g[1] not in list:
list.append(g[1])
result = dfs(g[1], list, graph, result)
if g[1] == a and g[0] not in list:
list.append(g[0])
result = dfs(g[0], list, graph, result)
return result
for g in graph:
list = []
if g[0] == "1":
list.append(1)
result += dfs("1", list, graph, 0)
print(result)
|
s507506682 | p03805 | u958958520 | 1596906266 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9224 | 573 | import sys
n,m = map(int,input().split())
graph = [list(input().split(" ")) for i in range(n)]
result=0
def dfs(a, list, graph, result):
print(list)
if len(list) == n:
result = result + 1
for g in graph:
if g[0] == a and g[1] not in list:
list.append(g[1])
result = dfs(g[1], list, graph, result)
if g[1] == a and g[0] not in list:
list.append(g[0])
result = dfs(g[0], list, graph, result)
return result
for g in graph:
list = []
if g[0] == "1":
list.append(1)
result += dfs("1", list, graph, 0)
print(result)
|
s342077369 | p03805 | u338597441 | 1596661675 | Python | Python (3.8.2) | py | Runtime Error | 37 | 9152 | 478 | import itertools as it
import sys
N, M = map(int, input().split())
if N==0 or M==0:
print(0)
sys.exit()
a=[]
for i in range(N):
x,y=map(int,input().split())
a.append([x,y])
a.append([y,x])
ans=0
for e in it.permutations(range(N)):
if e[0]!=0:
break
count=1
for j in range(N-1):
if [e[j]+1,e[j+1]+1] in a:
count*=1
else:
count*=0
break
ans+=count
print(ans) |
s911142375 | p03805 | u338597441 | 1596661054 | Python | Python (3.8.2) | py | Runtime Error | 40 | 9020 | 478 | import itertools as it
import sys
N, M = map(int, input().split())
if N==0 or M==0:
print(0)
sys.exit()
a=[]
for i in range(N):
x,y=map(int,input().split())
a.append([x,y])
a.append([y,x])
ans=0
for e in it.permutations(range(N)):
if e[0]!=0:
break
count=1
for j in range(M-1):
if [e[j]+1,e[j+1]+1] in a:
count*=1
else:
count*=0
break
ans+=count
print(ans) |
s778668999 | p03805 | u338597441 | 1596660632 | Python | Python (3.8.2) | py | Runtime Error | 33 | 9096 | 423 | import itertools as it
N, M = map(int, input().split())
a=[]
for i in range(N):
x,y=map(int,input().split())
a.append([x,y])
a.append([y,x])
ans=0
for e in it.permutations(range(N)):
if e[0]!=0:
break
count=1
for j in range(M-1):
if [e[j]+1,e[j+1]+1] in a:
count*=1
else:
count*=0
break
ans+=count
print(ans)
|
s747462476 | p03805 | u102655885 | 1596309257 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9068 | 931 | from collections import defaultdict
n, m = map(lambda x: int(x), input().split())
links = defaultdict(set)
for _ in range(m):
a, b = map(lambda x: int(x), input().split())
links[a].add(b)
links[b].add(a)
path_counter = 0
def path_patterns_number(current_node, remaining_nodes):#, remaining_links):
# print(current_node, remaining_nodes)
if len(remaining_nodes) == 0:
return 1
patterns = 0
for next_node in (links[current_node] & remaining_nodes):
# remaining_links_copy = remaining_links.copy()
# remaining_links_copy[current_node].remove(next_node) <=浅いコピーなので元のからもremoveされてる
patterns += path_patterns_number(
next_node,
remaining_nodes.copy() - {next_node}
# remaining_links_copy
)
return patterns
print(path_patterns_number(1, set(range(2,n+1)))#, links)) |
s774541324 | p03805 | u747703115 | 1596200994 | Python | Python (3.8.2) | py | Runtime Error | 25 | 8920 | 490 | import itertools
from math import factorial as fa
P = itertools.permutations(list(range(n)))
n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
a,b = map(lambda x:int(x)-1, input().split())
G[a].add(b)
G[b].add(a)
ans = 0
for _ in range(fa(n)):
p = next(P)
if p[0] != 0:
break
f = True
for pnw,pnx in zip(p,p[1:]):
if not pnx in G[pnw]:
f = False
break
if f:
ans += 1
print(ans) |
s483219666 | p03805 | u841111730 | 1596039396 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9076 | 599 |
#入力
N,M = map(int,input().split())
graph = [ ]
for _ in range(N+1):
graph.append([])
for _ in range(M):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
visited = []
for _ in range(N+1):
visited.append(False)
def dfs(dep,cur):
global N,visited,graph
if dep == N:
ans += 1
return 1
ans = 0
for dist in graph[cur]:
if visited[dist] == False:
visited[dist] = True
ans += dfs(dep + 1,dist)
visited[dist] = False
return ans
visited[1] = True
dfs(1,1)
print(ans)
|
s194421127 | p03805 | u364386647 | 1595376198 | Python | Python (3.8.2) | py | Runtime Error | 526 | 9536 | 601 | from itertools import permutations
import copy
def resolve():
N, M = list(map(int, input().split()))
G = [[0]*N for _ in range(M)]
for i in range(M):
a, b = list(map(int, input().split()))
G[a-1][b-1] = 1
G[b-1][a-1] = 1
ls = list(permutations(range(1, N)))
ans = 0
for l in ls:
h = copy.deepcopy(G)
cnt = 1
p = 0
for k in l:
if h[p][k] == 0:
break
else:
cnt += 1
p = k
if cnt == N:
ans += 1
print(ans)
return
resolve() |
s037677139 | p03805 | u618369407 | 1594924493 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9224 | 1250 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p and tmp_p[1] not in visited:
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[1])
#print(*tmp_visited)
# 次の頂点
next_p = tmp_p[1]
#print('next_p: ', next_p)
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# 往復対象の削除
tmp_p_r = [tmp_p[1], tmp_p[0]]
tmp_comb.remove(tmp_p_r)
#print(*tmp_comb)
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = [1]
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s807901847 | p03805 | u618369407 | 1594924345 | Python | Python (3.8.2) | py | Runtime Error | 29 | 9048 | 1222 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p:
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[1])
#print(*tmp_visited)
# 次の頂点
next_p = tmp_p[1]
#print('next_p: ', next_p)
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# 往復対象の削除
tmp_p_r = [tmp_p[1], tmp_p[0]]
tmp_comb.remove(tmp_p_r)
#print(*tmp_comb)
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = [1]
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s826787267 | p03805 | u618369407 | 1594923594 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9244 | 1208 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(set(visited)) == p_num - 1:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p:
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# 往復対象の削除
tmp_p_r = [tmp_p[1], tmp_p[0]]
tmp_comb.remove(tmp_p_r)
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[0])
#print(*tmp_visited, sep='')
# 次の頂点
next_p = tmp_p[1]
#print('next_p: ', next_p)
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = []
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s155767903 | p03805 | u618369407 | 1594923156 | Python | Python (3.8.2) | py | Runtime Error | 29 | 9216 | 1267 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num - 1:
#print('get the paass!!')
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p and tmp_p[0] not in visited:
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# 往復対象の削除
tmp_p_r = [tmp_p[1], tmp_p[0]]
tmp_comb.remove(tmp_p_r)
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[0])
#print(*tmp_visited, sep='')
# 次の頂点
next_p = tmp_p[1]
#print('next_p: ', tmp_p[1])
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = []
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s131765007 | p03805 | u618369407 | 1594922393 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9180 | 1124 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num - 1:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p and tmp_p[0] not in visited:
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# 往復対象の削除
tmp_p_r = [tmp_p[1], tmp_p[0]]
tmp_comb.remove(tmp_p_r)
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[0])
next_p = tmp_p[1]
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = []
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s503532805 | p03805 | u618369407 | 1594921672 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9240 | 1036 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num - 1:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p and tmp_p[0] not in visited and tmp_p[1] not in visited:
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[0])
next_p = tmp_p[1]
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = []
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s646789411 | p03805 | u618369407 | 1594921240 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9096 | 1145 | # -*- coding: utf-8 -*-
# 関数定義
def dfs(now_p, visited, comb_p, p_num):
# N頂点と同じ数のルートを通ったら有効なパスとして1を返す
if len(visited) == p_num - 1:
return 1
ans = 0
# now_pの検索
for tmp_p in comb_p:
if tmp_p[0] == now_p and tmp_p[0] not in visited and tmp_p[1] not in visited:
# comb_pのtmp
tmp_comb = comb_p[:]
tmp_comb.remove(tmp_p)
#print(*tmp_comb)
# visitedのtmp
tmp_visited = visited[:]
tmp_visited.append(tmp_p[0])
#print('visited :', tmp_p[0])
next_p = tmp_p[1]
#print('next :', next_p)
# dfsの再起呼び出し
ans += dfs(next_p, tmp_visited, tmp_comb, p_num)
return ans
## 入力読み取り
N, M = map(int, input().split())
a_b = []
tmp = []
tmp_r = []
# 辺読み取り
for i in range(N):
tmp = list(map(int, input().split()))
tmp_r = [tmp[1], tmp[0]]
a_b.append(tmp)
a_b.append(tmp_r)
visited = []
# 再起関数の実施
pass_num = dfs(1, visited, a_b, N)
print(pass_num) |
s654222061 | p03805 | u595952233 | 1594866882 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9240 | 557 | import sys
sys.setrecursionlimit(10**8)
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n):
a, b = map(int, input().split())
a-=1; b-=1
g[a].append(b)
g[b].append(a)
used = [False] * n
ans = 0
def dfs(itr, n, cnt=0):
ans = 0
if len(itr)==n:
return 1
else:
ans = cnt
for e in g[itr[-1]]:
if used[e]:
continue
used[e] = True
ans+=dfs(itr+[e], n)
used[e] = False
return ans
used[0] = True
print(dfs([0], n, 0)) |
s447628210 | p03805 | u595952233 | 1594866214 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9180 | 549 | import sys
sys.setrecursionlimit(10**8)
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n):
a, b = map(int, input().split())
a-=1; b-=1
g[a].append(b)
g[b].append(a)
used = [False] * n
ans = 0
def dfs(itr, n, cnt=0):
if len(itr)==n:
return 1
else:
ans = cnt
for e in g[itr[-1]]:
if used[e]:
continue
used[e] = True
ans+=dfs(itr+[e], n)
used[e] = False
return ans
used[0] = True
print(dfs([0], n, 0)) |
s196516368 | p03805 | u595952233 | 1594865702 | Python | Python (3.8.2) | py | Runtime Error | 31 | 9232 | 677 | import sys
sys.setrecursionlimit(10**8)
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n):
a, b = map(int, input().split())
a-=1; b-=1
g[a].append(b)
g[b].append(a)
used = [False] * n
ans = 0
def dfs(itr, n, cnt=0):
if len(itr)==n:
return 1
elif len(itr)==0:
ans = cnt
for i in range(n):
used[i] = True
ans += dfs([i], n)
return ans
else:
ans = cnt
for e in g[itr[-1]]:
if used[e]:
continue
used[e] = True
ans+=dfs(itr+[e], n)
used[e] = False
return ans
print(dfs([], n, 0)) |
s788029291 | p03805 | u595952233 | 1594865679 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9244 | 637 | n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n):
a, b = map(int, input().split())
a-=1; b-=1
g[a].append(b)
g[b].append(a)
used = [False] * n
ans = 0
def dfs(itr, n, cnt=0):
if len(itr)==n:
return 1
elif len(itr)==0:
ans = cnt
for i in range(n):
used[i] = True
ans += dfs([i], n)
return ans
else:
ans = cnt
for e in g[itr[-1]]:
if used[e]:
continue
used[e] = True
ans+=dfs(itr+[e], n)
used[e] = False
return ans
print(dfs([], n, 0)) |
s983263602 | p03805 | u454557108 | 1594276133 | Python | Python (3.8.2) | py | Runtime Error | 113 | 26984 | 513 | # -*- coding: utf-8 -*-
import numpy as np
n,m = map(int, input().split())
graph = [[] for j in range(n)]
graph = np.array(graph)
for i in range(m):
a,b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
used = [False]*n
used[0] = True
def DFS(v,used):
if all(used):
return 1
ans = 0
for i in graph(v):
if used[i]:
continue
used[i] = True
ans += DFS(i,used)
used[i] = False
return ans
print(DFS(0,used)) |
s090249858 | p03805 | u454557108 | 1594276097 | Python | Python (3.8.2) | py | Runtime Error | 111 | 27148 | 532 | # -*- coding: utf-8 -*-
import numpy as np
n,m = map(int, input().split())
graph = [[0 for i in range(n)] for j in range(n)]
graph = np.array(graph)
for i in range(m):
a,b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
used = [False]*n
used[0] = True
def DFS(v,used):
if all(used):
return 1
ans = 0
for i in graph(v):
if used[i]:
continue
used[i] = True
ans += DFS(i,used)
used[i] = False
return ans
print(DFS(0,used)) |
s826555564 | p03805 | u405660020 | 1594153117 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9080 | 432 | n,m=map(int,input().split())
graph=[[]*n for _ in range(n)]
for _ in range(n):
a,b=map(int,input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def dfs(v, seen):
if all(seen):
return 1
ans=0
for vv in graph[v]:
if seen[vv]:
continue
seen[vv]=True
ans+=dfs(vv, seen)
seen[vv]=False
return ans
seen=[False]*n
seen[0]=True
print(dfs(0, seen))
|
s287721699 | p03805 | u506549878 | 1593768736 | Python | Python (3.8.2) | py | Runtime Error | 289 | 9160 | 840 | import itertools
N,M = map(int,input().split())
L=[]
for i in range(M):
a,b=map(int,input().split())
L.append([a,b])
number=[]
for i in range(1,N+1):
number.append(i)
ans=0
for v in itertools.permutations(number,N):
a=0
v=list(v)
for j in range(N-1):
if ([v[j],v[j+1]] not in L ) and ([v[j+1],v[j]] not in L):
a=1
if a==0 and v[0]==1:
ans+=1
print(ans)
import itertools
N,M = map(int,input().split())
L=[]
for i in range(M):
a,b=map(int,input().split())
L.append([a,b])
number=[]
for i in range(1,N+1):
number.append(i)
ans=0
for v in itertools.permutations(number,N):
a=0
v=list(v)
for j in range(N-1):
if ([v[j],v[j+1]] not in L ) and ([v[j+1],v[j]] not in L):
a=1
if a==0 and v[0]==1:
ans+=1
print(ans)
|
s212489641 | p03805 | u912650255 | 1593654752 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9072 | 455 | N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
route = itertools.permutations([i for i in range(2,N+1)])
ans = 0
for i in route:
count = 0
for j in range(M):
a,b = ab[j][0],ab[j][1]
if i.index(a) == i.index(b)+1 or i.index(a) == i.index(b)-1:
count += 1
if count == M-1:
ans +=1
if count == M-1:
ans +=1
print(ans) |
s477248517 | p03805 | u912650255 | 1593653769 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9124 | 461 | import itertools
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
print(ab)
route = itertools.permutations([i for i in range(2,N+1)])
print(list(route_1))
ans = 0
for i in route:
count = 0
for j in range(M):
a,b = ab[j][0],ab[j][1]
if i.index(a) == i.index(b)+1 or i.index(a) == i.index(b)-1:
count += 1
print(count,i)
if count == M-1:
ans +=1 |
s267953821 | p03805 | u729119068 | 1593454463 | Python | Python (3.8.2) | py | Runtime Error | 27 | 8952 | 276 | import itertools
N,M=map(int,input().split())
edges={tuplec(sorted(map(int,input().split()))) for i in range(M)}
ans=0
for i in itertools.permutations(range(2,N+1),N-1):
l=[1]+list(i)
ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1
print(ans) |
s633933338 | p03805 | u729119068 | 1593454392 | Python | Python (3.8.2) | py | Runtime Error | 26 | 8920 | 272 | import itertools
N,M=map(int,input().split())
edges={tuplec(sorted(map(int,input().split()))) for i in range(M)}
ans=0
for i in itertools.permutations(range(2,N+1)):
l=[1]+list(i)
ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1
print(ans) |
s915689007 | p03805 | u163783894 | 1593225768 | Python | PyPy3 (7.3.0) | py | Runtime Error | 87 | 74892 | 910 | import sys
import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
sys.setrecursionlimit(1000000)
ans = 0
def bfs(N, edge, v, search):
search |= {v}
global ans
if len(search) == N:
ans += 1
return
for e in edge[v]:
if e not in search:
#print('test:{},{},{}'.format(e, v, search))
bfs(N, edge, e, copy.copy(search))
def main():
N, M = in_nn()
edge = [[] for _ in range(M)]
for i in range(M):
a, b = in_nn()
a, b = a - 1, b - 1
edge[a].append(b)
edge[b].append(a)
bfs(N, edge, 0, set())
print(ans)
if __name__ == '__main__':
main()
|
s809951326 | p03805 | u759987571 | 1592879973 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9012 | 714 | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;
int main(){
int n,m;
cin>>n>>m;
vv road(n, vi (n,0));
rep(i,m){
int a,b;
cin >> a >> b;
a--;b--;
road[a][b] = 1;
road[b][a] = 1;
}
vi p(n);
rep(i,n)p[i]=i;
int ans = 0;
do{
bool ok = true;
if(p[0]!=0)continue;
for(int i=1; i<n; i++){
if(road[p[i-1]][p[i]])continue;
ok = false;
break;
}
if(ok)ans++;
} while(next_permutation(p.begin(), p.end()));
cout << ans << endl;
return 0;
} |
s614124162 | p03805 | u679390859 | 1592873412 | Python | Python (3.8.2) | py | Runtime Error | 23 | 8960 | 399 | N,M = map(int,input(),aplit())
path = [[] for i in range(N)]
for _ in range(M):
a,b = map(int,input(),split())
path[a-1],append(b-1)
path[b-1],append(a-1)
vis = [0 for i in range(N)]
cnt = 0
def dfs(now,path):
global cnt
if depth == N: cnt+=1
for new in path[now]:
if vis[new] == 0:
vis[new] = 1
dfs(new,depth+1)
vis[new] = 0
vis[0] = 1
dfs(0,1)
print(cnt) |
s320464368 | p03805 | u131881594 | 1592848356 | Python | Python (3.8.2) | py | Runtime Error | 23 | 9208 | 288 | import itertools as it
n,m=map(int,input().split())
path={[] for _ in range(m)}
for i in range(m): path[i]=list(map(int,input().split()))
ls=list(it.permutations(range(1,n+1)))
cnt=0
for l in ls:
if l[0]==1: break
for i in range(n-1):
if [i,i+1] in path: cnt+=1
print(cnt) |
s249427183 | p03805 | u188138642 | 1592783162 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9152 | 393 | N, M = map(int, input().split())
ab = [[] for _ in range(M)]
for _ in range(M):
a, b = map(int,input().split())
ab[a-1].append(b-1)
ab[b-1].append(a-1)
count = 0
def dfs(i, now, done):
global count
if i == N-1:
count += 1
return
for j in ab[now]:
if j not in done:
dfs(i+1, j, done + [j])
return
dfs(0, 0, [0])
print(count)
|
s292074911 | p03805 | u188138642 | 1592782652 | Python | Python (3.8.2) | py | Runtime Error | 34 | 9208 | 392 | N, M = map(int, input().split())
ab = [[] for _ in range(M)]
for _ in range(M):
a, b = map(int,input().split())
ab[a-1].append(b-1)
ab[b-1].append(a-1)
count = 0
def dfs(i, now, done):
global count
if i == N-1:
count += 1
return
for j in ab[now]:
if j not in done:
dfs(i+1, j, done + [j])
return
dfs(0, 0, [0])
print(count) |
s480603121 | p03805 | u221061152 | 1592623651 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9204 | 340 | n,m=map(int,input().split())
ab = []
for _ in range(n):
a,b=map(int,input().split())
a,b=a-1,b-1
ab.append({a,b})
import itertools
cnt = 0
for v in itertools.permutations(range(1,n)):
l = 0
ok = True
for v2 in v:
if {l,v2} not in ab:
ok = False
break
l = v2
if ok:
#print(v)
cnt += 1
print(cnt) |
s341710144 | p03805 | u221061152 | 1592623634 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9196 | 339 | n,m=map(int,input().split())
ab = []
for _ in range(n):
a,b=map(int,input().split())
a,b=a-1,b-1
ab.append({a,b})
import itertools
cnt = 0
for v in itertools.permutations(range(1,n)):
l = 0
ok = True
for v2 in v:
if {l,v2} not in ab:
ok = False
break
l = v2
if ok:
print(v)
cnt += 1
print(cnt) |
s380587623 | p03805 | u221061152 | 1592623324 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9196 | 334 | n,m=map(int,input().split())
ab = []
for _ in range(n):
a,b=map(int,input().split())
a,b=a-1,b-1
ab.append({a,b})
import itertools
cnt = 0
for v in itertools.permutations(range(1,n)):
l = 0
ok = True
for v2 in v:
if {l,v2} not in ab:
ok = False
break
l = v2
if ok == True:
cnt += 1
print(cnt) |
s915390436 | p03805 | u101350975 | 1592599880 | Python | Python (3.8.2) | py | Runtime Error | 21 | 8960 | 453 | import itertools
n, m = map(int, input().split())
path = [[False] * n for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
path[a][b] = True
path[b][a] = True
ans = 0
for i itertools.permutations(range(n), n):
if i[0] == 0:
for j in range(n):
if j == n - 1:
ans += 1
break
if not path[i[j]][i[j+1]]:
break
print(ans)
|
s461492770 | p03805 | u730769327 | 1592589405 | Python | PyPy3 (7.3.0) | py | Runtime Error | 101 | 74644 | 345 | def ser(visited,now):
visited.append(now)
if len(visited)==n:
return 1
cnt=0
for i in bri[now]:
if i not in visited:
cnt+= ser(visited[:],i)
return cnt
n,m=map(int,input().split())
bri=[[] for _ in range(m)]
for i in range(m):
a,b=map(int,input().split())
bri[a-1].append(b-1)
bri[b-1].append(a-1)
print(ser([],0)) |
s452964227 | p03805 | u325282913 | 1592543700 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9348 | 505 | import copy
import sys
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
edges = [[] for _ in range(M)]
for _ in range(M):
a, b = map(int, input().split())
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
ans = 0
def dfs(start,path):
next_path = copy.copy(path)
global ans
next_path.append(start)
if len(next_path) == N:
ans += 1
return
for i in edges[start]:
if i not in next_path:
dfs(i,next_path)
dfs(0,[])
print(ans) |
s389190422 | p03805 | u453815934 | 1592162224 | Python | Python (3.4.3) | py | Runtime Error | 160 | 13296 | 590 | import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,input().split())
def i() : return int(input())
from scipy.special import perm #print(perm(4,2,exact=True))=4P2=3
a,b=mi()
ans=0
l=[[] for _ in range(a)]
for i in range(b):
u,v=mi()
l[u-1].append(v-1)
l[v-1].append(u-1)
S=[]
for i in range(1,a):
S.append(i)
lst=list(itertools.permutations(S))
for i in lst:
x=0
t=True
for w in range(len(i)):
if not i[w] in l[x]:
t=False
break
x=i[w]
if t:
ans+=1
print(ans) |
s568952215 | p03805 | u453815934 | 1592162139 | Python | Python (3.4.3) | py | Runtime Error | 187 | 14944 | 580 | import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,input().split())
def i() : return int(input())
from scipy.special import perm #print(perm(4,2,exact=True))=4P2=3
a,b=mi()
ans=0
l=[[] for _ in range(a)]
for i in range(b):
u,v=mi()
l[u-1].append(v-1)
l[v-1].append(u-1)
S=[]
for i in range(1,a):
S.append(i)
lst=list(permutations(S))
for i in lst:
x=0
t=True
for w in range(len(i)):
if not i[w] in l[x]:
t=False
break
x=i[w]
if t:
ans+=1
print(ans) |
s233435306 | p03805 | u414920281 | 1591958369 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3064 | 426 | import itertools
n,m=map(int,input().split())
path=[[False]*n for i in range(n)]
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
path[a][b]=True
path[b][a]=True
ans=0;
for i in itertools.permutations(range(n),n):
if i[0]==0:
for j in range(n):
if j==n-1:
ans+=1
break
if not path[i[j]][i[j]+1]:
break
print(ans) |
s752828824 | p03805 | u045628053 | 1591924484 | Python | PyPy3 (2.4.0) | py | Runtime Error | 177 | 38384 | 401 | n,m = list(map(int,input().split()))
p_list = [list(map(int,input().split())) for i in range(n)]
import itertools
p_con = list(itertools.combinations(p_list,n-1))
output =0
for con in p_con:
bou= sum(con,[])
syuten = 0
for i in range(2,n+1):
if bou.count(i) == 1 and syuten == 0:
syuten = i
elif bou.count(i) != 2:
break
else:
output += 1
continue
print(output) |
s054347243 | p03805 | u707124227 | 1591915340 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 406 | n,m=map(int,input().split())
g=[[]for _ in range(n)]
for _ in range(n):
a,b=map(int,input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
import sys
sys.setrecursionlimit(10**7)
def dfs(t,seen):
if all(seen):
return 1
ret=0
l=g[t]
for li in l:
if seen[li]==0:
seenli=seen.copy()
seenli[li]=1
ret+=dfs(li,seenli)
return ret
seen=[0]*n
seen[0]=1
print(dfs(0,seen)) |
s701090905 | p03805 | u105290050 | 1591757141 | Python | Python (3.4.3) | py | Runtime Error | 64 | 3064 | 459 | import itertools as itl
n, m=map(int, input().split())
#ここでリストを作成する
hen=[]
check=0
if m==0:
print(0)
exit()
for _ in range(m):
hen.append(list(map(int, input().split())))
#print(hen)
l=list(range(2, n+1))
for v in itl.permutations(l):
#print(v)
for i in range(n-2):
if not(sorted(v[i:i+2]) in hen) or not(list([1, v[0]]) in hen):
break
else:
if i==n-3:
check+=1
continue
print(check)
|
s060401986 | p03805 | u105290050 | 1591756921 | Python | Python (3.4.3) | py | Runtime Error | 63 | 3064 | 441 | import itertools as itl
n, m=map(int, input().split())
#ここでリストを作成する
hen=[]
check=0
for _ in range(m):
hen.append(list(map(int, input().split())))
#print(hen)
l=list(range(2, n+1))
for v in itl.permutations(l):
#print(v)
for i in range(n-2):
if not(sorted(v[i:i+2]) in hen) or not(list([1, v[0]]) in hen):
break
else:
if i==n-3:
check+=1
continue
break
print(check)
|
s302410167 | p03805 | u105290050 | 1591756715 | Python | Python (3.4.3) | py | Runtime Error | 64 | 3064 | 450 | import itertools as itl
n, m=map(int, input().split())
#ここでリストを作成する
hen=[]
check=0
for _ in range(m):
hen.append(tuple(map(int, input().split())))
#print(hen)
l=list(range(2, n+1))
for v in itl.permutations(l):
#print(v)
for i in range(n-2):
if not(tuple(sorted(v[i:i+2])) in hen) or not(tuple([1, v[0]]) in hen):
break
else:
if i==n-3:
check+=1
continue
break
print(check)
|
s433939038 | p03805 | u105290050 | 1591756424 | Python | Python (3.4.3) | py | Runtime Error | 64 | 3064 | 470 | import itertools as itl
n, m=map(int, input().split())
#ここでリストを作成する
hen=[]
check=0
for _ in range(m):
hen.append(tuple(map(int, input().split())))
#print(hen)
l=list(range(2, n+1))
for v in itl.permutations(l):
#print(v)
for i in range(n-2):
if not(tuple(sorted(v[i:i+2])) in hen) or not(tuple([1, v[0]]) in hen):
#print(sorted(v[i:i+2]))
break
else:
if i==n-3:
check+=1
continue
print(check)
|
s956208555 | p03805 | u517910772 | 1591504124 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3444 | 783 | def abc054_c_one_stroke_paths():
import copy
N, E = map(int, input().split())
# create graph G
G = {}
for m in range(M):
a, z = map(int, input().split())
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1, 0) == 0:
print(0)
return
paths = []
def solve(a, path):
path.append(a)
if len(path) == N:
paths.append(path)
return
for z in G.get(a):
p = copy.copy(path)
if z in p:
continue
solve(z, p)
solve(1, [])
# print(paths)
print(len(paths))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
|
s325606590 | p03805 | u517910772 | 1591503928 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3444 | 783 | def abc054_c_one_stroke_paths():
import copy
N, E = map(int, input().split())
# create graph G
G = {}
for n in range(N):
a, z = map(int, input().split())
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
# print(G)
# find all paths
if G.get(1) is None:
print(0)
return
paths = []
def solve(a, path):
path.append(a)
if len(path) == N:
paths.append(path)
return
for z in G.get(a):
p = copy.copy(path)
if z in p:
continue
solve(z, p)
solve(1, [])
# print(paths)
print(len(paths))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
|
s238694906 | p03805 | u517910772 | 1591503867 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3444 | 796 | def abc054_c_one_stroke_paths():
import copy
N, E = map(int, input().split())
# create graph G
G = {}
for n in range(N):
a, z = map(int, input().split())
G[a] = G.get(a, [])
G[a].append(z)
G[z] = G.get(z, [])
G[z].append(a)
print(G)
# find all paths
if G.get(1) is None:
print(0)
return
paths = []
def solve(a, path):
path.append(a)
if len(path) == N:
paths.append(path)
return
for z in G.get(a):
p = copy.copy(path)
print(p, a, z)
if z in p:
continue
solve(z, p)
solve(1, [])
print(paths, len(paths))
##########
if __name__ == "__main__":
abc054_c_one_stroke_paths()
|
s066126651 | p03805 | u868982936 | 1591473011 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 313 |
from itertools import permutations
V, E = map(int, input().split())
edges = {tuple(map(int, input().split())) for _ in range(E)}
ans = 0
for route in permutations(range(2, n+1)):
route = [1] + list(route)
ans += len([1 for edge in zip(route, route[1:]) if tuple(sorted(edges)) in edges]) == n - 1
print(ans) |
s639230353 | p03805 | u987170100 | 1591236087 | Python | Python (3.4.3) | py | Runtime Error | 36 | 3064 | 528 | import sys
sys.setrecursionlimit(10 ** 7)
N, M = map(int, input().split())
visited = [0 for _ in range(N)]
graph = [[0] * M for _ in range(M)]
for _ in range(M):
a, b = map(int, input().split())
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
def dfs(i, depth):
if visited[i]:
return 0
if depth == N - 1:
return 1
visited[i] = 1
ret = 0
for j in range(0, N):
if graph[i][j]:
ret += dfs(j, depth + 1)
visited[i] = 0
return ret
print(dfs(0, 0)) |
s330421085 | p03805 | u987170100 | 1591236036 | Python | Python (3.4.3) | py | Runtime Error | 37 | 3064 | 529 | import sys
sys.setrecursionlimit(1000000)
N, M = map(int, input().split())
visited = [0 for _ in range(N)]
graph = [[0] * M for _ in range(M)]
for _ in range(M):
a, b = map(int, input().split())
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
def dfs(i, depth):
if visited[i]:
return 0
if depth == N - 1:
return 1
visited[i] = 1
ret = 0
for j in range(0, N):
if graph[i][j]:
ret += dfs(j, depth + 1)
visited[i] = 0
return ret
print(dfs(0, 0))
|
s900555909 | p03805 | u987170100 | 1591235985 | Python | Python (3.4.3) | py | Runtime Error | 36 | 3064 | 527 | import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
visited = [0 for _ in range(N)]
graph = [[0] * M for _ in range(M)]
for _ in range(M):
a, b = map(int, input().split())
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
def dfs(i, depth):
if visited[i]:
return 0
if depth == N - 1:
return 1
visited[i] = 1
ret = 0
for j in range(0, N):
if graph[i][j]:
ret += dfs(j, depth + 1)
visited[i] = 0
return ret
print(dfs(0, 0)) |
s226965702 | p03805 | u987170100 | 1591235861 | Python | Python (3.4.3) | py | Runtime Error | 36 | 3064 | 485 | N, M = map(int, input().split())
visited = [0 for _ in range(N)]
graph = [[0] * M for _ in range(M)]
for _ in range(M):
a, b = map(int, input().split())
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
def dfs(i, depth):
if visited[i]:
return 0
if depth == N - 1:
return 1
visited[i] = 1
ret = 0
for j in range(0, N):
if graph[i][j]:
ret += dfs(j, depth + 1)
visited[i] = 0
return ret
print(dfs(0, 0))
|
s898728941 | p03805 | u991134049 | 1591041199 | Python | PyPy3 (2.4.0) | py | Runtime Error | 207 | 42972 | 492 | def DFS(now, visited):
ans = 0
if all(visited):
return 1
for i in range(N):
if path[now][i] and visited[i] == False:
visited[i] = True
ans += DFS(i, visited)
visited[i] = False
return ans
N, M = map(int, input().split())
path = [[0]*N for i in range(M)]
for i in range(M):
a, b = map(int, input().split())
path[a-1][b-1] = 1
path[b-1][a-1] = 1
visited = [False]*N
visited[0] = True
print(DFS(0, visited))
|
s145448300 | p03805 | u540290227 | 1590762957 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 157 | n, m = map(int, input().split())
count = 0
for i in range(n):
a, b = map(int, input().split())
if a == 1 or b == 1:
count += 1
print(count) |
s660826927 | p03805 | u462329577 | 1590717388 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3316 | 671 | #!/usr/bin/env python3
# input
from collections import deque
import itertools
n, m = map(int, input().split())
a, b = [0] * (n), [0] * (n)
path = [[] for _ in range(n)]
for i in range(m):
a[i], b[i] = map(int, input().split())
a[i] -= 1
b[i] -= 1
path[a[i]].append(b[i])
path[b[i]].append(a[i])
# n-1 ! を全探索する
all_lis = itertools.permutations(range(1, n)) # 1(0)は出発点なので除く
# print(all_lis)
ans = 0
for i in all_lis:
start = 0
ok = 1
for j in range(n - 1):
if i[j] not in path[start]:
ok = 0
break
else:
start = i[j]
if ok:
ans += 1
print(ans)
|
s550043071 | p03805 | u462329577 | 1590717246 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3316 | 671 | #!/usr/bin/env python3
# input
from collections import deque
import itertools
n, m = map(int, input().split())
a, b = [0] * (n), [0] * (n)
path = [[] for _ in range(n)]
for i in range(m):
a[i], b[i] = map(int, input().split())
a[i] -= 1
b[i] -= 1
path[a[i]].append(b[i])
path[b[i]].append(a[i])
# n-1 ! を全探索する
all_lis = itertools.permutations(range(1, n)) # 1(0)は出発点なので除く
# print(all_lis)
ans = 0
for i in all_lis:
start = 0
ok = 1
for j in range(n - 1):
if i[j] not in path[start]:
ok = 0
break
else:
start = i[j]
if ok:
ans += 1
print(ans)
|
s279668958 | p03805 | u174181999 | 1590638606 | Python | Python (3.4.3) | py | Runtime Error | 41 | 3064 | 449 | import sys
sys.setrecursionlimit(100000000)
N, M = map(int, input().split())
adj = [[] for _ in range(M)]
visited = [0] * N
for i in range(M):
a, b = map(int, input().split())
adj[a-1].append(b)
adj[b-1].append(a)
ans = []
def dfs(x):
visited[x-1] = 1
if visited == [1] * N:
ans.append(1)
for i in range(len(adj[x-1])):
if visited[adj[x-1][i] - 1] == 0:
dfs(adj[x-1][i])
visited[x-1] = 0
dfs(1)
print(sum(ans)) |
s534138977 | p03805 | u174181999 | 1590638567 | Python | Python (3.4.3) | py | Runtime Error | 44 | 3064 | 446 | import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
adj = [[] for _ in range(M)]
visited = [0] * N
for i in range(M):
a, b = map(int, input().split())
adj[a-1].append(b)
adj[b-1].append(a)
ans = []
def dfs(x):
visited[x-1] = 1
if visited == [1] * N:
ans.append(1)
for i in range(len(adj[x-1])):
if visited[adj[x-1][i] - 1] == 0:
dfs(adj[x-1][i])
visited[x-1] = 0
dfs(1)
print(sum(ans)) |
s236717646 | p03805 | u174181999 | 1590638446 | Python | Python (3.4.3) | py | Runtime Error | 42 | 3064 | 404 | N, M = map(int, input().split())
adj = [[] for _ in range(M)]
visited = [0] * N
for i in range(M):
a, b = map(int, input().split())
adj[a-1].append(b)
adj[b-1].append(a)
ans = []
def dfs(x):
visited[x-1] = 1
if visited == [1] * N:
ans.append(1)
for i in range(len(adj[x-1])):
if visited[adj[x-1][i] - 1] == 0:
dfs(adj[x-1][i])
visited[x-1] = 0
dfs(1)
print(sum(ans)) |
s530580617 | p03805 | u811436126 | 1590550100 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 521 | import sys
sys.setrecursionlimit(500 * 500)
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
def dfs(now, depth):
if visit[now]:
return 0
if depth == n:
return 1
count = 0
visit[now] = 1
if graph[now]:
for i in graph[now]:
count += dfs(i, depth + 1)
visit[now] = 0
return count
ans = dfs(1, 1)
print(ans)
|
s481757377 | p03805 | u811436126 | 1590549722 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 527 | import sys
sys.setrecursionlimit(500 * 500)
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
ans = 0
def dfs(now, depth):
global ans
if visit[now]:
pass
if depth == n:
ans += 1
visit[now] = 1
if graph[now]:
for i in graph[now]:
if visit[i] == 0:
dfs(i, depth + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
|
s259291017 | p03805 | u811436126 | 1590549688 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3316 | 512 | from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
ans = 0
def dfs(now, depth):
global ans
if visit[now]:
pass
if depth == n:
ans += 1
visit[now] = 1
if graph[now]:
for i in graph[now]:
if visit[i] == 0:
dfs(i, depth + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
|
s797081055 | p03805 | u811436126 | 1590549518 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3316 | 481 | from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
ans = 0
def dfs(now, depth):
global ans
if visit[now]:
pass
if depth == n:
ans += 1
visit[now] = 1
for i in graph[now]:
if visit[i] == 0:
dfs(i, depth + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
|
s224656360 | p03805 | u811436126 | 1590549156 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3316 | 693 | from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
q = deque([1])
while q:
now = q.popleft()
visit[now] = 1
for i in graph[now]:
if visit[i] == 0:
q.append(i)
def dfs(now, count, seen):
global ans
if count == depth:
ans += 1
else:
for i in graph[now]:
if seen[i] == 0:
seen[now] = 1
dfs(i, count + 1, seen)
seen[now] = 0
depth = sum(visit)
ans = 0
seen = [0] * (n + 1)
dfs(1, 1, seen)
print(ans)
|
s551333564 | p03805 | u811436126 | 1590548183 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3316 | 725 | from collections import deque
import sys
sys.setrecursionlimit(500 * 500)
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
q = deque([1])
while q:
now = q.popleft()
visit[now] = 1
for i in graph[now]:
if visit[i] == 0:
q.append(i)
depth = sum(visit)
ans = 0
visit = [0] * (n + 1)
def dfs(now, count):
global ans
if count == depth:
ans += 1
else:
for i in graph[now]:
if visit[i] == 0:
visit[now] = 1
dfs(i, count + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
|
s415300238 | p03805 | u811436126 | 1590547870 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3316 | 680 | from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
q = deque([1])
while q:
now = q.popleft()
visit[now] = 1
for i in graph[now]:
if visit[i] == 0:
q.append(i)
depth = sum(visit)
ans = 0
visit = [0] * (n + 1)
def dfs(now, count):
global ans
if count == depth:
ans += 1
else:
for i in graph[now]:
if visit[i] == 0:
visit[now] = 1
dfs(i, count + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
|
s557171833 | p03805 | u033963510 | 1590543164 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3444 | 964 |
N , M = map(int, input().split())
def mkmap(N, M):
mapdic = {}
for i in range(1, M+1):
mapdic[str(i)] = []
for j in range(N):
pathA, pathB = map(str, input().split())
mapdic[pathA] = mapdic[pathA] + [pathB]
mapdic[pathB] = mapdic[pathB] + [pathA]
return mapdic
mapdic = mkmap(N, M)
import copy
roots = [[]]*N
roots[0] = ["1"]
for i in range(N-1):
root = copy.deepcopy(roots[i])
for nowroot in root:
for nextroot in mapdic[nowroot[-1]]:
if i >= 1:
if not nextroot in nowroot:
roots[i+1] = roots[i+1] + [nowroot + nextroot]
else:
pass
else:
roots[i+1] = roots[i+1] + [nowroot + nextroot]
List = [str(n+1) for n in range(N)]
check = "".join(List)
ans = 0
for i in roots[-1]:
TF = "".join(sorted(list(i))) == check
if TF:
ans = ans + 1
print(ans)
|
s020284079 | p03805 | u033963510 | 1590542030 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3444 | 810 |
N , M = map(int, input().split())
def mkmap(N, M):
mapdic = {}
for i in range(1, M+1):
mapdic[str(i)] = []
for j in range(N):
pathA, pathB = map(str, input().split())
mapdic[pathA] = mapdic[pathA] + [pathB]
mapdic[pathB] = mapdic[pathB] + [pathA]
return mapdic
mapdic = mkmap(N, M)
import copy
roots = [[]]*N
roots[0] = ["1"]
for i in range(N-1):
root = copy.deepcopy(roots[i])
for nowroot in root:
for nextroot in mapdic[nowroot[-1]]:
if i >= 1:
if not nextroot in nowroot:
roots[i+1] = roots[i+1] + [nowroot + nextroot]
else:
pass
else:
roots[i+1] = roots[i+1] + [nowroot + nextroot]
print(len(roots[-1])) |
s694684093 | p03805 | u440129511 | 1590535948 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 734 | import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
g=nx.Graph()
g.add_edges_from(s)
#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
a,b=s[i][0],s[i][1]
l[a-1].append(b)
l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l1.insert(0,1)
l_depth=list(dict.fromkeys(l1))#深さのリスト
# スタート地点からゴール地点までのすべての単純路 (同じ頂点を通らないパス)
k=list(nx.all_simple_paths(g, source=1, target=l_depth[-1]))
c=0
ma=0
for i in range(len(k)):
if len(k[i])>ma:
ma=len(k[i])
c-=c+1
if len(k[i])==ma:
c+=1
print(c) |
s757292871 | p03805 | u440129511 | 1590535832 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 736 | import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
g=nx.Graph()
g.add_edges_from(s)
#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
a,b=s[i][0],s[i][1]
l[a-1].append(b)
l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l1.insert(0,1)
l_depth=list(dict.fromkeys(l1))#深さのリスト
# スタート地点からゴール地点までのすべての単純路 (同じ頂点を通らないパス)
k=list(nx.all_simple_paths(g, source=1, target=l_depth[-1]))
c=0
ma=0
for i in range(len(k)):
if len(k[i])>ma:
ma=len(k[i])
c-=c+1
elif len(k[i])==ma:
c+=1
print(c) |
s432871510 | p03805 | u440129511 | 1590535490 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 736 | import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
g=nx.Graph()
g.add_edges_from(s)
#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
a,b=s[i][0],s[i][1]
l[a-1].append(b)
l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l1.insert(0,1)
l_depth=list(dict.fromkeys(l1))#深さのリスト
# スタート地点からゴール地点までのすべての単純路 (同じ頂点を通らないパス)
k=list(nx.all_simple_paths(G, source=1, target=l_depth[-1]))
c=0
ma=0
for i in range(len(k)):
if len(k[i])>ma:
ma=len(k[i])
c-=c+1
elif len(k[i])==ma:
c+=1
print(c) |
s340076308 | p03805 | u440129511 | 1590517998 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 728 | import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
g=nx.Graph()
g.add_edges_from(s)
#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
a,b=s[i][0],s[i][1]
l[a-1].append(b)
l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l1.insert(0,1)
l_depth=list(dict.fromkeys(l1))#深さのリスト
# スタート地点からゴール地点までのすべての単純路 (同じ頂点を通らないパス)
k=list(nx.all_simple_paths(G, source=1, target=l_depth[-1]))
c=0
ma=0
for i in range(k):
if len(k[i])>ma:
ma=len(k[i])
c-=c+1
elif len(k[i])==ma:
c+=1
print(c) |
s791786160 | p03805 | u166201488 | 1590366163 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 360 | import itertools
N, M = map(int, input().split())
p = [list(map(int, input().split())) for i in range(M)]
v = list(map(list, itertools.permutations(range(2,N+1), N-1)))
cnt = 0
for i in range(len(v)):
vit = True
v_i = [1]+v[i]
for j in range(N-1):
if sorted(v_i[j:j+2]) not in p:
vit = False
if vit:
cnt += 1
print(cnt) |
s738041100 | p03805 | u991134049 | 1590346472 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38256 | 546 | N, M = map(int, input().split())
pathmat=[[0]*N for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
pathmat[a-1][b-1] = 1
pathmat[b-1][a-1] = 1
visited = [False]*N
visited[0] = True
ans = 0
def DFS(now, visited):
if all(visited):
return 1
for i in range(N):
if not pathmat[now][i]:
continue
if visited[i]:
continue
visited[i]=True
ans += DFS(i, visited)
visited[i]=False
return ans
print(DFS(0,visited))
|
s835766170 | p03805 | u658987783 | 1590173824 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 307 | from itertools import permutations
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]
ans=0
x=[i for i in range(2,n+1)]
cand=permutations(x)
for i in cand:
crnt=1
for nxt in i:
if set([crnt,nxt]) in s:
crnt=nxt
else:
break
else:
ans+=1
print(ans) |
s437601224 | p03805 | u658987783 | 1590173739 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 299 | import itertools
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]
ans=0
x=[i for i in range(2,n+1)]
cand=itertools.permutations(x)
for i in cand:
crnt=1
for nxt in i:
if set([crnt,nxt]) in s:
crnt=nxt
else:
break
else:
ans+=1
print(ans) |
s970519990 | p03805 | u658987783 | 1590173718 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 320 | import itertools
n,m=map(int,input().split())
s=[set(map(int,input().split())) for _ in range(n)]
ans=0
x=[i for i in range(2,n+1)]
print(x)
cand=itertools.permutations(x)
print(cand)
for i in cand:
crnt=1
for nxt in i:
if set([crnt,nxt]) in s:
crnt=nxt
else:
break
else:
ans+=1
print(ans) |
s853329090 | p03805 | u115418613 | 1590155469 | Python | Python (3.4.3) | py | Runtime Error | 35 | 8052 | 552 | import sys
input = sys.stdin.readline
import itertools
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for n in range(N)]
branch = [[False]* N for n in range(N)]
for m in range(M):
a = ab[m][0] - 1
b = ab[m][1] -1
branch[a][b] = True
branch[b][a] = True
ans = 0
pattern = list(itertools.permutations(range(1, N+1),N))
for l in pattern:
if l[0] != 1:
continue
for n in range(N):
if n == N - 1:
ans += 1
break
p = l[n] -1
np = l[n+1] -1
if not(branch[p][np]):
break
print(ans) |
s190642928 | p03805 | u115418613 | 1590155158 | Python | Python (3.4.3) | py | Runtime Error | 2222 | 1720608 | 553 | import sys
input = sys.stdin.readline
import itertools
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for m in range(M)]
branch = [[False]* N for n in range(N)]
for m in range(M):
a = ab[m][0] - 1
b = ab[m][1] -1
branch[a][b] = True
branch[b][a] = True
ans = 0
pattern = list(itertools.permutations(range(1, M+1),M))
for l in pattern:
if l[0] != 1:
continue
for m in range(M):
if m == M - 1:
ans += 1
break
p = l[m] -1
np = l[m+1] -1
if not(branch[p][np]):
break
print(ans) |
s136348096 | p03805 | u686036872 | 1589886291 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 425 | N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
visited = [0]*N
ans = 0
visited[0] = 1
def dfs(v):
if 0 not in visited:
return 1
for i in G[v]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0)) |
s969271336 | p03805 | u686036872 | 1589885059 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 435 | N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1] = b-1
G[b-1] = a-1
visited = [0]*N
visited[0] = 1
def dfs(v, visited):
if 0 not in visited:
return 1
ans = 0
for i in G[v]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0, visited)) |
s344550966 | p03805 | u686036872 | 1589884822 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 437 | N, M = map(int, input().split())
G = [[]*N for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1] = b-1
G[b-1] = a-1
visited = [0]*N
visited[0] = 1
def dfs(v, visited):
if 0 not in visited:
return 1
ans = 0
for i in G[v]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0, visited)) |
s625768011 | p03805 | u686036872 | 1589884783 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 438 | N, M = map(int, input().split())
G = [[0]*N for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1] = b-1
G[b-1] = a-1
visited = [0]*N
visited[0] = 1
def dfs(v, visited):
if 0 not in visited:
return 1
ans = 0
for i in G[v]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0, visited)) |
s882696199 | p03805 | u686036872 | 1589884203 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 448 | N, M = map(int, input().split())
G = [[0]*N for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1][b - 1] = 1
G[b-1][a - 1] = 1
visited = [0]*N
visited[0] = 1
def dfs(v, visited):
if 0 not in visited:
return 1
ans = 0
for i in G[x]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0, visited)) |
s712040623 | p03805 | u686036872 | 1589884145 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 445 | N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1][b - 1] = 1
G[b-1][a - 1] = 1
visited = [0]*N
visited[0] = 1
def dfs(v, visited):
if 0 not in visited:
return 1
ans = 0
for i in G[x]:
if visited[i] == 0:
visited[i] = 1
ans += dfs(i, visited)
visited[i] = 0
return ans
print(dfs(0, visited)) |
s739445633 | p03805 | u707960254 | 1589759951 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38384 | 637 | import itertools
import numpy as np
N, M = map(int, input().split())
X = [[] for _ in range(M)]
for i in range(M):
X[i] = list(map(int, input().split()))
permutations_list = list(itertools.permutations([i for i in range(N-1)]))
count = 0
for i in range(len(permutations_list)):
x = np.argsort(permutations_list[i])
if [1, x[0]+2] not in X and [x[0]+2, 1] not in X:
count += 1
continue
for j in range(N-2):
pair = [x[j]+2, x[j+1]+2]
reverse = list(reversed(pair))
if pair not in X and reverse not in X:
count += 1
break
print(len(permutations_list) -count) |
s707727251 | p03805 | u629350026 | 1589721298 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 194 | import itertools
n,m=map(int,input().split())
edge=[0]*m
ans=0
for i in range(0,m):
a,b=map(int,input().split())
edge[i]=[a,b]
edge.sort
print(edge)
if len(node)==0:
ans=ans+1
print(ans) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.