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
s380560989
p03805
u094191970
1571377714
Python
Python (3.4.3)
py
Runtime Error
30
3064
467
from itertools import permutations n,m=map(int,input().split()) tree=[[] for i in range(m)] for i in range(m): a,b=map(int,input().split()) tree[a-1].append(b-1) tree[b-1].append(a-1) cnt=0 for i in permutations(range(1,n)): if i[0] in tree[0]: t_cnt=1 for j in range(1,len(i)): if i[j] in tree[i[j-1]]: t_cnt+=1 else: break if t_cnt==n-1: cnt+=1 print(cnt)
s346829767
p03805
u094191970
1571377656
Python
Python (3.4.3)
py
Runtime Error
30
3064
467
from itertools import permutations n,m=map(int,input().split()) tree=[[] for i in range(m)] for i in range(m): a,b=map(int,input().split()) tree[a-1].append(b-1) tree[b-1].append(a-1) cnt=0 for i in permutations(range(1,n)): if i[0] in tree[0]: t_cnt=1 for j in range(1,len(i)): if i[j] in tree[i[j-1]]: t_cnt+=1 else: break if t_cnt==m-1: cnt+=1 print(cnt)
s082189523
p03805
u094191970
1571377367
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
42632
427
from itertools import permutations n,m=map(int,input().split()) tree=[[] for i in range(m)] for i in range(m): a,b=map(int,input().split()) tree[a-1].append(b-1) tree[b-1].append(a-1) cnt=0 for i in permutations(range(1,m)): if i[0] in tree[0]: t_cnt=1 for j in range(1,len(i)): if i[j] in tree[i[j-1]]: t_cnt+=1 if t_cnt==m-1: cnt+=1 print(cnt)
s473001470
p03805
u094191970
1571376735
Python
Python (3.4.3)
py
Runtime Error
2104
3064
427
from itertools import permutations n,m=map(int,input().split()) tree=[[] for i in range(m)] for i in range(m): a,b=map(int,input().split()) tree[a-1].append(b-1) tree[b-1].append(a-1) cnt=0 for i in permutations(range(1,m)): if i[0] in tree[0]: t_cnt=1 for j in range(1,len(i)): if i[j] in tree[i[j-1]]: t_cnt+=1 if t_cnt==m-1: cnt+=1 print(cnt)
s708453802
p03805
u022154897
1571179107
Python
PyPy3 (2.4.0)
py
Runtime Error
170
38512
676
from collections import defaultdict def c(): n, m = map(int, input().split()) graph = defaultdict(list) a1 = None for i in range(n): a, b = map(int, input().split()) if i == 0: a1 = a graph[a].append(b) graph[b].append(a) stack = [] count = 0 if a1: stack.append((a1, set())) while stack: val, visited = stack.pop() visited.add(val) if len(visited) == m: count += 1 continue for g in graph[val]: if g not in visited: stack.append((g, set(visited))) print(count) if __name__ == '__main__': c()
s197289338
p03805
u123648284
1570915039
Python
Python (3.4.3)
py
Runtime Error
18
3064
418
def bfs(u): if used.count(True) == N: res[0] += 1 return for v in adj[u]: if used[v]: continue used[v] = True bfs(v) used[v] = False N, M = map(int, input().split()) adj = [[] for i in range(N)] for i in range(N): u, v = map(lambda x: int(x)-1, input().split()) adj[u].append(v) adj[v].append(u) used = [False for i in range(N)] used[0] = True res = [0] bfs(0) print(res[0])
s446103400
p03805
u223646582
1569988203
Python
Python (3.4.3)
py
Runtime Error
19
3064
376
import itertools N, M = map(int, input().split()) G = {k: set() for k in range(N+1)} for _ in range(N): a, b = map(int, input().split()) # 無向グラフ G[a].add(b) G[b].add(a) ans = 0 for p in itertools.permutations(range(2, N+1)): c = 1 for n in p: if n not in G[c]: break c = n else: ans += 1 print(ans)
s082370707
p03805
u893478938
1569682768
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38384
550
def resolve(): N,M = map(int,input().split()) ab =[map(int,input().split()) for _ in range(N)] branch = [[] for _ in range(N)] for a,b in ab: branch[a-1].append(b-1) branch[b-1].append(a-1) bit = 0 count = 0 def walk(p): nonlocal bit,N bit |= (1 << p) if bit == 2 ** N - 1: nonlocal count count += 1 for n in branch[p]: if not(bit & (1 << n)): walk(n) bit &= ~(1 << p) walk(0) print(count) resolve()
s154625798
p03805
u090267744
1569641258
Python
Python (3.4.3)
py
Runtime Error
17
2940
652
#C One-stroke Path import itertools import numpy as np n,m=map(int,input().split( )) adj_matrix=np.zeros((n,n)) for i in range(m): a,b=map(int,input().split( )) adj_matrix[a-1,b-1]=1 adj_matrix[b-1,a-1]=1 cnt=0 for each in itertools.permutations(range(n)): #頂点の全ての並べ方(permutation) if each[0] != 0:#始点が1ではないものを除外した。breakすることで次のeachに変わる。 break factor=1 for i in range(n-1): #全経路があれば全て1になるのでfactor=1となりcntに足される。 factor *=adj_matrix[each[i],each[i+1]] cnt += factor print(int(cnt))
s601057728
p03805
u780962115
1569464201
Python
Python (3.4.3)
py
Runtime Error
18
3064
517
n,m=map(int,input().split()) uselist=[] for _ in range(m): ad=list(map(int,input().split())) uselist.append(ad) cnt=0 for i in itertools.permutations(range(1,n+1)): if i[0]==1: flag=True for j in range(n-1): if [i[j],i[j+1]] not in uselist and [i[j+1], i[j]] not in uselist: flag =False break else: continue if flag==True: cnt+=1 else: continue print(cnt)
s364094263
p03805
u598229387
1569341938
Python
Python (3.4.3)
py
Runtime Error
32
3064
378
import itertools n,m=map(int,input().split()) edge=[[]for i in range(m+1)] for i in range(m): a,b=map(int,input().split()) edge[a].append(b) edge[b].append(a) ans=0 for i in itertools.permutations(range(1,n+1)): if i[0]!=1: continue for j in range(n-1): if i[j+1] not in edge[i[j]]: break else: ans+=1 print(ans)
s023435645
p03805
u433532588
1568946241
Python
Python (3.4.3)
py
Runtime Error
18
3064
747
import sys input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # A = [ int(input()) for _ in range(N) ] ############################## N, M = map(int, input().split()) A = [ [0 for _ in range(N)] for _ in range(N) ] visited = [False] * N for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 A[a][b] = 1 A[b][a] = 1 #print(A) def dfs(node, count): if all(visited): return 1 count = 0 for i in range(M): if A[node][i] == 0: continue if visited[i]: continue visited[i] = True count += dfs(i, count) visited[i] = False return count visited[0] = True count = dfs(0, 0) print(count)
s142688517
p03805
u433532588
1568946158
Python
Python (3.4.3)
py
Runtime Error
18
3064
737
import sys input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # A = [ int(input()) for _ in range(N) ] ############################## N, M = map(int, input().split()) A = [ [0 for _ in range(N)] for _ in range(N) ] visited = [False] * N for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 A[a][b] = 1 A[b][a] = 1 #print(A) def dfs(node, count): if all(visited): return count+1 for i in range(M): if A[node][i] == 0: continue if visited[i]: continue visited[i] = True count = dfs(i, count) visited[i] = False return count visited[0] = True count = dfs(0, 0) print(count)
s954840983
p03805
u432551953
1568860671
Python
Python (3.4.3)
py
Runtime Error
92
3064
529
import sys input = sys.stdin.readline from operator import itemgetter import itertools def main(): n, m = map(int, input().strip().split()) lis = [[] for _ in range(n)] for _ in range(m): a, b = list(map(lambda x: x-1, map(int, input().strip().split()))) lis[a].append(b) lis[b].append(a) ans = 0 for path in itertools.permutations(range(8), 8): if all(path[i+1] in lis[path[i]] for i in range(n-1)): ans += 1 print(ans) if __name__ == '__main__': main()
s754151809
p03805
u432551953
1568860594
Python
PyPy3 (2.4.0)
py
Runtime Error
216
43116
529
import sys input = sys.stdin.readline from operator import itemgetter import itertools def main(): n, m = map(int, input().strip().split()) lis = [[] for _ in range(n)] for _ in range(m): a, b = list(map(lambda x: x-1, map(int, input().strip().split()))) lis[a].append(b) lis[b].append(a) ans = 0 for path in itertools.permutations(range(8), 8): if all(path[i+1] in lis[path[i]] for i in range(n-1)): ans += 1 print(ans) if __name__ == '__main__': main()
s351104205
p03805
u378328623
1568754734
Python
Python (3.4.3)
py
Runtime Error
17
3064
521
N, M = map(int, input().split()) edgelist = [] for i in range(N): edgelist.append(set(map(int, input().split()))) s = [1] count = 0 L = [[i for i in edgelist if (len(i&set([1]))!=0)]] while s != []: if len(s) == M: count = count + 1 L.pop() s.pop() elif L[-1] == []: L.pop() s.pop() else: p = L[-1].pop() r = list(p - set([s[-1]])) L.append([i for i in edgelist if (len(i&set(r))!=0)*(len(i&set(s))==0)]) s.append(r[0]) print(count)
s074223224
p03805
u325227960
1568700958
Python
PyPy3 (2.4.0)
py
Runtime Error
186
40816
553
n, m = map(int,input().split()) A = [list(map(int,input().split())) for i in range(n)] import itertools M = [[0] * (n+1) for i in range(n+1)] for i in range(m): M[A[i][0]][A[i][1]] = 1 M[A[i][1]][A[i][0]] = 1 B = list(itertools.permutations(range(2, n+1))) #print(B) ans = 0 for i in range(len(B)): pt = 0 if M[1][B[i][0]] == 1: pt += 1 else: continue for j in range(len(B[i])-1): if M[B[i][j]][B[i][j+1]] == 1: pt += 1 # print(B[i],pt) if pt == n-1: ans += 1 print(ans)
s395670796
p03805
u390883247
1568537381
Python
Python (3.4.3)
py
Runtime Error
31
3064
597
import itertools N,M = map(int,input().split()) Data = [] for _ in range(M+1): Data.append([0]*(M+1)) for _ in range(M): a,b = map(int,input().split()) Data[a][b] = 1 Data[b][a] = 1 ans = 0 for r in itertools.permutations(range(2,N+1)): Rlist = list(r) a = 1 b = Rlist[0] if Data[a][b] == 0: continue else: flag = True for i in range(len(Rlist)-1): a = Rlist[i] b = Rlist[i+1] if Data[a][b] == 0: flag = False break if flag: ans += 1 print(ans)
s980251120
p03805
u189326411
1568076671
Python
Python (3.4.3)
py
Runtime Error
26
3064
445
import itertools n,m = map(int, input().split()) path = [[False]*n for _ in range(n)] for i in range(n): 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)
s111643800
p03805
u311379832
1567997619
Python
Python (3.4.3)
py
Runtime Error
25
3064
579
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, M = map(int, input().split()) tLst = [[] for _ in range(M)] vLst = [0] * N for i in range(M): a, b = map(int, input().split()) tLst[a - 1].append(b - 1) tLst[b - 1].append(a - 1) def dfs(n, index, v, ans): vLst[index] = 1 if n == N - 1: ans += 1 return ans for i in tLst[index]: if v == i: continue elif vLst[i] == 1: continue ans = dfs(n + 1, i, index, ans) vLst[i] = 0 return ans print(dfs(0, 0, 0, 0))
s928217085
p03805
u871841829
1567983782
Python
Python (3.4.3)
py
Runtime Error
22
3444
674
import copy N, M = list(map(int, input().split())) graph = [[-1 for _ in range(N)] for __ in range(N)] cnt = 0 def solve(current: int, traversed: set): global cnt traversed = copy.copy(traversed) # fail if current in traversed: return else: traversed.add(current) # success if len(traversed) == N: cnt += 1 return # traverse for node_ix in range(N): if graph[current][node_ix] == 1: solve(node_ix, traversed) # Create adjcent graph for _ in range(N): a, b = list(map(lambda x: int(x)-1, input().split())) graph[a][b] = 1 graph[b][a] = 1 solve(0, set()) print(cnt)
s883623200
p03805
u463858127
1567662716
Python
Python (3.4.3)
py
Runtime Error
24
3064
546
# import sys # sys.setrecursionlimit(10**9) N, M = map(int, input().split()) Map = [[] for _ in range(M)] reached = [False]*N for _ in range(M): aa, bb = map(int, input().split()) Map[aa-1].append(bb-1) Map[bb-1].append(aa-1) cnt = 0 def DFS(x): global cnt global reached reached[x] = True if all(reached): cnt += 1 reached[x] = False return for i in Map[x]: if reached[i]: continue else: DFS(i) reached[x] = False DFS(0) print(cnt)
s708746231
p03805
u463858127
1567662644
Python
Python (3.4.3)
py
Runtime Error
24
3064
542
import sys sys.setrecursionlimit(10**9) N, M = map(int, input().split()) Map = [[] for _ in range(M)] reached = [False]*N for _ in range(M): aa, bb = map(int, input().split()) Map[aa-1].append(bb-1) Map[bb-1].append(aa-1) cnt = 0 def DFS(x): global cnt global reached reached[x] = True if all(reached): cnt += 1 reached[x] = False return for i in Map[x]: if reached[i]: continue else: DFS(i) reached[x] = False DFS(0) print(cnt)
s126141309
p03805
u463858127
1567555319
Python
Python (3.4.3)
py
Runtime Error
17
3064
502
import sys sys.setrecursionlimit(10**20) N, M = map(int, input().split()) Map = [[] for _ in range(M)] reached = [False]*N for _ in range(M): aa, bb = map(int, input().split()) Map[aa-1].append(bb-1) Map[bb-1].append(aa-1) cnt = 0 def DFS(x): global cnt reached[x] = True if all(reached): cnt += 1 for i in range(N): if reached[i]: continue if i in Map[x]: DFS(i) reached[x] = False return DFS(0) print(cnt)
s099676803
p03805
u463858127
1567554204
Python
Python (3.4.3)
py
Runtime Error
31
3064
501
import sys sys.setrecursionlimit(10**9) N, M = map(int, input().split()) Map = [[] for _ in range(M)] reached = [False]*N for _ in range(M): aa, bb = map(int, input().split()) Map[aa-1].append(bb-1) Map[bb-1].append(aa-1) cnt = 0 def DFS(x): global cnt reached[x] = True if all(reached): cnt += 1 for i in range(N): if reached[i]: continue if i in Map[x]: DFS(i) reached[x] = False return DFS(0) print(cnt)
s513593014
p03805
u463858127
1567552923
Python
Python (3.4.3)
py
Runtime Error
32
3064
511
import sys sys.setrecursionlimit(10**9) N, M = map(int, input().split()) Map = [[] for _ in range(M)] reached = [False]*N for _ in range(M): aa, bb = map(int, input().split()) Map[aa-1].append(bb-1) Map[bb-1].append(aa-1) cnt = 0 def DFS(x, pre): global cnt reached[x] = True if all(reached): cnt += 1 for i in range(N): if i==pre or reached[i]: continue if i in Map[x]: DFS(i, x) reached[x] = False DFS(0,-1) print(cnt)
s925261895
p03805
u408620326
1567458860
Python
Python (3.4.3)
py
Runtime Error
19
3064
557
N, M = [int(x) for x in input().split()] P = [[False] * M for m in range(M)] dict={} for m in range(M): a, b = [int(x) for x in input().split()] P[a-1][b-1] = True P[b-1][a-1] = True def dp(x, past): past[x] = True if (x, tuple(past)) in dict: return dict[(x, tuple(past))] if False not in past: return 1 ret = 0 for i,p in enumerate(P[x]): if not p or x == i or past[i]: continue else: ret += dp(i, past[:]) dict[(x, tuple(past))] = ret return ret if M < N - 1: print(0) else: print(dp(0, [False] * N))
s715643418
p03805
u408620326
1567385732
Python
Python (3.4.3)
py
Runtime Error
43
3064
566
import sys sys.setrecursionlimit(1000000) N, M = [int(x) for x in input().split()] P = [[False] * M for m in range(M)] dict={} for m in range(M): a, b = [int(x) for x in input().split()] P[a-1][b-1] = True P[b-1][a-1] = True def dp(x, past): if (x, tuple(past)) in dict: return dict[(x, tuple(past))] past[x] = True if False not in past: return 1 ret = 0 for i,p in enumerate(P[x]): if not p or x == i or past[i]: continue else: ret += dp(i, past[:]) dict[(x, tuple(past))] = ret return ret print(dp(0, [False] * N))
s097575178
p03805
u408620326
1567385710
Python
Python (3.4.3)
py
Runtime Error
42
3188
564
import sys sys.setrecursionlimit(10000) N, M = [int(x) for x in input().split()] P = [[False] * M for m in range(M)] dict={} for m in range(M): a, b = [int(x) for x in input().split()] P[a-1][b-1] = True P[b-1][a-1] = True def dp(x, past): if (x, tuple(past)) in dict: return dict[(x, tuple(past))] past[x] = True if False not in past: return 1 ret = 0 for i,p in enumerate(P[x]): if not p or x == i or past[i]: continue else: ret += dp(i, past[:]) dict[(x, tuple(past))] = ret return ret print(dp(0, [False] * N))
s991310077
p03805
u408620326
1567385276
Python
Python (3.4.3)
py
Runtime Error
44
3316
524
N, M = [int(x) for x in input().split()] P = [[False] * M for m in range(M)] dict={} for m in range(M): a, b = [int(x) for x in input().split()] P[a-1][b-1] = True P[b-1][a-1] = True def dp(x, past): if (x, tuple(past)) in dict: return dict[(x, tuple(past))] past[x] = True if False not in past: return 1 ret = 0 for i,p in enumerate(P[x]): if not p or x == i or past[i]: continue else: ret += dp(i, past[:]) dict[(x, tuple(past))] = ret return ret print(dp(0, [False] * N))
s268738903
p03805
u408620326
1567384703
Python
Python (3.4.3)
py
Runtime Error
34
3064
420
N, M = [int(x) for x in input().split()] P = [[False] * M for m in range(M)] for m in range(M): a, b = [int(x) for x in input().split()] P[a-1][b-1] = True P[b-1][a-1] = True def dp(x, past): past[x] = True if False not in past: return 1 ret = 0 for i,p in enumerate(P[x]): if not p or x == i or past[i]: continue else: ret += dp(i, past[:]) return ret print(dp(0, [False] * N))
s762852481
p03805
u500297289
1567024098
Python
Python (3.4.3)
py
Runtime Error
1822
708980
451
import sys sys.setrecursionlimit(1000000) N, M = map(int, input().split()) edge = [[] for _ in range(N + 1)] ab = [list(map(int, input().split())) for _ in range(M)] for i in range(M): a, b = ab[i][0], ab[i][1] edge[a].append(b) edge[b].append(a) def f(now, v): v = v & (1 << now) for to in edge[now]: if v >> to == 0: f(to, v) if v == int('0b11111111', 0): ans += 1 ans = 0 f(1, 1) print(ans)
s927486416
p03805
u981931040
1566951152
Python
Python (3.4.3)
py
Runtime Error
27
3064
603
n , m = map(int , input().split()) edge = [[] for _ in range(m) ] #print(edge) for _ in range(m): a , b = map(int , input().split()) a -= 1 ; b -= 1 edge[a].append(b) edge[b].append(a) #print(edge) def DFS(s): global visited #ret=1 if all(visited) else 0 if all(visited): ret = 1 else: ret = 0 for e in edge[s]: #print("e",e) if visited[e] == True: continue visited[e] = True ret += DFS(e) visited[e] = False return ret ans = 0 visited = [False] * n visited[0] = True ans += DFS(0) print(ans)
s661195235
p03805
u981931040
1566950668
Python
Python (3.4.3)
py
Runtime Error
28
3064
603
n , m = map(int , input().split()) edge = [[] for _ in range(m) ] #print(edge) for _ in range(m): a , b = map(int , input().split()) a -= 1 ; b -= 1 edge[a].append(b) edge[b].append(a) #print(edge) def DFS(s): global visited #ret=1 if all(visited) else 0 if all(visited): ret = 1 else: ret = 0 for e in edge[s]: #print("e",e) if visited[e] == True: continue visited[e] = True ret += DFS(e) visited[e] = False return ret ans = 0 visited = [False] * n visited[0] = True ans += DFS(0) print(ans)
s813933110
p03805
u981931040
1566950569
Python
Python (3.4.3)
py
Runtime Error
18
3064
583
n , m = map(int , input().split()) edge = [[] for _ in range(m) ] #print(edge) for _ in range(m): a , b = map(int , input().split()) a -= 1 ; b -= 1 edge[a].append(b) edge[b].append(a) #print(edge) def DFS(s): global visited #ret=1 if all(visited) else 0 if all(visited): ret = 1 else: ret = 0 for e in edge[s]: #print("e",e) if visited[e] == True: continue visited[e] = True ret += DFS(e) visited[e] = False return ret visited = [False] * n visited[0] = True print(DFS[0])
s118451669
p03805
u981931040
1566950518
Python
Python (3.4.3)
py
Runtime Error
17
3064
581
n , m = map(int , input().split()) edge = [[] for _ in range(m) ] #print(edge) for _ in range(m): a , b = map(int , input().split()) a -= 1 ; b -= 1 edge[a].append(b) edge[b].append(a) print(edge) def DFS(s): global visited #ret=1 if all(visited) else 0 if all(visited): ret = 1 else: ret = 0 for e in edge[s]: print("e",e) if visited[e] == True: continue visited[e] = True ret += DFS(e) visited[e] = False return ret visited = [False] * n visited[0] = True print(DFS[0])
s112472451
p03805
u155687575
1566768383
Python
PyPy3 (2.4.0)
py
Runtime Error
201
40560
414
import itertools n, m = map(int, input().split()) adj_matrix = [[0] * n for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) adj_matrix[a-1][b-1] = 1 adj_matrix[b-1][a-1] = 1 cnt = 0 for each in range(itertools.permutations(range(n))): if each[0] != 0: break flag = 1 for i in range(n-1): flag *= adj_matrix[each[i]][each[i+1]] cnt += flag print(cnt)
s688003401
p03805
u433532588
1566701375
Python
Python (3.4.3)
py
Runtime Error
17
3064
745
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## # N = 頂点の数(= 数字の数) # M = 辺の数(= aの行数) N, M = map(int, input().split()) graph = [ [0 for _ in range(N)] for _ in range(N) ] visited = [False] * N for i in range(N): a, b = map(int, input().split()) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 #print(graph) # u は 0-index def dfs(u): visited[u] = True if False in visited: pass else: return 1 count = 0 for i in range(N): if graph[u][i] == False: continue if visited[i]: continue visited[i] = True count += dfs(i) visited[i] = False return count count = dfs(0) print(count)
s724537166
p03805
u433532588
1566701245
Python
Python (3.4.3)
py
Runtime Error
17
3064
679
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N, M = map(int, input().split()) graph = [ [0 for _ in range(M)] for _ in range(M) ] visited = [False] * M for i in range(N): a, b = map(int, input().split()) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 #print(graph) # u は 0-index def dfs(u): visited[u] = True if False in visited: pass else: return 1 count = 0 for i in range(N): if graph[u][i] == False: continue if visited[i]: continue visited[i] = True count += dfs(i) visited[i] = False return count count = dfs(0) print(count)
s014526694
p03805
u433532588
1566700991
Python
Python (3.4.3)
py
Runtime Error
18
3064
689
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N, M = map(int, input().split()) graph = [ [0 for _ in range(M)] for _ in range(M) ] visited = [False] * M for i in range(N): a, b = map(int, input().split()) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 #print(graph) # u は 0-index def dfs(u): visited[u] = True if False in visited: pass else: return 1 count = 0 for i in range(M): if graph[u][i] == False: continue if visited[i]: continue visited[i] = True count += dfs(i) visited[i] = False return count count = 0 count = dfs(0) print(count)
s162574050
p03805
u433532588
1566700743
Python
Python (3.4.3)
py
Runtime Error
18
3188
698
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N, M = map(int, input().split()) graph = [ [0 for _ in range(M)] for _ in range(M) ] visited = [False] * M for i in range(N): a, b = map(int, input().split()) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 #print(graph) # u は 0-index count = 0 def dfs(u, count): visited[u] = True if False in visited: pass else: count += 1 for i in range(M): if graph[u][i] == False: continue if visited[i]: continue visited[i] = True count = dfs(i, count) visited[i] = False return count count = dfs(0, count) print(count)
s464177201
p03805
u531436689
1566413301
Python
Python (3.4.3)
py
Runtime Error
68
6684
1130
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() N, M = LI() mat = [[0] * N for _ in range(M)] for _ in range(M): a, b = LI_() mat[a][b] = 1 mat[b][a] = 1 seen = [0 for _ in range(N)] ans = 0 def dfs(i, count): global ans import pdb # pdb.set_trace() if count == N: return True for j, reachable in enumerate(mat[i]): if reachable and not seen[j]: seen[j] = 1 if dfs(j, count + 1): ans += 1 seen[j] = 0 return False def main(): seen[0] = 1 dfs(0, 1) print(ans) main()
s983211975
p03805
u852517668
1566322596
Python
PyPy3 (2.4.0)
py
Runtime Error
181
38384
419
from collections import deque N, M = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) G[a-1].append(b-1) G[b-1].append(a-1) ans = 0 v = 0 s = 1 l = 1 q = deque() q.append((v, s, l)) while q: v, s, l = q.popleft() if l == N: ans += 1 continue for nv in G[v]: if s&(1<<n) == 0: q.append((nv, s|(1<<n), l+1)) print(ans)
s360723847
p03805
u850491413
1565949298
Python
Python (3.4.3)
py
Runtime Error
18
3064
680
N, M = list(map(int,input().split())) graph = [dict() for i in range(N)] for i in range(N): graph[i]["edge"] = [] for i in range(M): a, b = list(map(int, input().split())) graph[a - 1]["edge"].append(b - 1) graph[b - 1]["edge"].append(a - 1) def pow(N): ans = 1 for i in range(N): ans *= i + 1 return ans total = 0 for i in range(pow(N - 1)): node = [a+1 for a in range(N - 1)] num = i zyun = [0] for j in range(N - 1, 0 , -1): mod = num % j num -= num % j num = num//j zyun.append(copy.deepcopy(node[mod])) del node[mod] judge = 1 for loc in range(N - 1): if not zyun[loc + 1] in graph[zyun[loc]]["edge"]: judge = 0 total += judge print(total)
s441126996
p03805
u098420017
1565845556
Python
Python (3.4.3)
py
Runtime Error
18
3064
496
n,m = map(int,input().split()) l=[[*map(int,input().split())] for _ in range(m)] i=[[] for _ in range(max(n,m))] i[0]=[1] c=1 for i_1 in i: for i_2 in i_1: a=[] for k in l: if i_2 in k: a.append(k) else: continue for b in a: if b[0]==i_2: i[c].append(b[1]) else: i[c].append(b[0]) for k in l[:]: if i_2 in k: l.remove(k) c+=1 print(len(i[n-2]))
s038805886
p03805
u098420017
1565844965
Python
Python (3.4.3)
py
Runtime Error
17
3064
490
n,m = map(int,input().split()) l=[[*map(int,input().split())] for _ in range(m)] i=[[] for _ in range(m)] i[0]=[1] c=1 for i_1 in i: for i_2 in i_1: a=[] for k in l: if i_2 in k: a.append(k) else: continue for b in a: if b[0]==i_2: i[c].append(b[1]) else: i[c].append(b[0]) for k in l[:]: if i_2 in k: l.remove(k) c+=1 print(len(i[n-2]))
s637705728
p03805
u098420017
1565844734
Python
Python (3.4.3)
py
Runtime Error
18
3064
490
n,m = map(int,input().split()) l=[[*map(int,input().split())] for _ in range(m)] i=[[] for _ in range(m)] i[0]=[1] c=1 for i_1 in i: for i_2 in i_1: a=[] for k in l: if i_2 in k: a.append(k) else: continue for b in a: if b[0]==i_2: i[c].append(b[1]) else: i[c].append(b[0]) for k in l[:]: if i_2 in k: l.remove(k) c+=1 print(len(i[m-2]))
s550172469
p03805
u098420017
1565844305
Python
Python (3.4.3)
py
Runtime Error
17
2940
3
 
s190958045
p03805
u229959388
1565807938
Python
Python (3.4.3)
py
Runtime Error
18
3064
651
def main(): n, m = map(int, input().split()) mat = [[0]*n for i in range(n)] l = [list(map(int, input().split())) for _ in range(m)] for i in range(n): mat[l[i][0]-1][l[i][1]-1] = 1 mat[l[i][1]-1][l[i][0]-1] = 1 ver = [i for i in range(n)] cnt = 0 def dfc(now, moved): nonlocal cnt moved.sort() if moved == ver: cnt += 1 for i in range(n): if (mat[now][i] == 0) or (i in moved): continue dfc(i, moved + [i]) dfc(0, [0]) print(cnt) if __name__ == "__main__": main()
s813083127
p03805
u229959388
1565807871
Python
Python (3.4.3)
py
Runtime Error
21
3188
1255
def main(): n, m = map(int, input().split()) mat = [[0]*n for i in range(n)] l = [list(map(int, input().split())) for _ in range(m)] for i in range(n): mat[l[i][0]-1][l[i][1]-1] = 1 mat[l[i][1]-1][l[i][0]-1] = 1 ver = [i for i in range(n)] cnt = 0 def dfc(now, moved): nonlocal cnt moved.sort() if moved == ver: cnt += 1 for i in range(n): if (mat[now][i] == 0) or (i in moved): continue dfc(i, moved + [i]) dfc(0, [0]) print(cnt) if __name__ == "__main__": main() def main(): n, m = map(int, input().split()) tree = [[]*n for i in range(n)] l = [list(map(int, input().split())) for _ in range(m)] for i in l: tree[i[0]-1].append(i[1]-1) tree[i[1]-1].append(i[0]-1) ver = [i for i in range(n)] cnt = 0 def dfc(now, moved): nonlocal cnt moved.sort() if moved == ver: cnt += 1 for i in tree[now]: if i in moved: continue dfc(i, moved + [i]) dfc(0, [0]) print(cnt) if __name__ == "__main__": main()
s636409879
p03805
u889344512
1565738145
Python
PyPy3 (2.4.0)
py
Runtime Error
182
38256
410
n, m = map(int,input().split()) ab = [[0 for i in range(n)] for j in range(n)] for i in range(m): ai,bi = map(int,input().split()) ab[ai-1][bi-1] = 1 ab[bi-1][ai-1] = 1 count = 0 def dfs(x,v): l = v.copy() l.append(x) if len(l)==n: global count count += 1 for i in range(n): if ab[x][i] == 1 and not i in l: dfs(i,l) dfs(0,[]) print(count)
s014879902
p03805
u408760403
1565644823
Python
Python (3.4.3)
py
Runtime Error
18
3064
569
N,M=map(int,input().split()) tbl=[[0]*(N+1) for _ in range(N+1)] for i in range(M): a,b=map(int,input().split()) tbl[a][b]=1 tbl[b][a]=1 # グラフの行列を用いた表現 def dfs(s,visited): if len(visited)==N: return 1 ans=0 for i in range(1,N+1): if i==s: continue #自己閉路は関係ない。 if tbl[s][i]==1 and (i not in visited): visited.append(i) ans+=dfs(i,visited) visited.pop()     #dfsを考えているからiをpopする。 return ans answer=dfs(1,[1,]) print(answer)
s927079802
p03805
u492447501
1565521382
Python
Python (3.4.3)
py
Runtime Error
22
3444
1041
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(M): lst.append([0]*N) for i in range(M): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 lst[idx2-1][idx1-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s402055470
p03805
u492447501
1565521115
Python
Python (3.4.3)
py
Runtime Error
23
3444
1041
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 lst[idx2-1][idx1-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s539978726
p03805
u492447501
1565520935
Python
Python (3.4.3)
py
Runtime Error
22
3444
1053
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True print(cur_node) print(pre_node) for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s166825589
p03805
u492447501
1565518807
Python
Python (3.4.3)
py
Runtime Error
22
3444
1029
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N-1: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True map[N-1] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s128626213
p03805
u492447501
1565518647
Python
Python (3.4.3)
py
Runtime Error
22
3444
1031
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N-1 or cur_node <= 0 or cur_node >= N-1: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True map[N-1] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s967351072
p03805
u492447501
1565518509
Python
Python (3.4.3)
py
Runtime Error
39
3956
1033
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N-1 or cur_node <= 0 or cur_node >= N-1: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True map[N-1] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N-1: graph_count = graph_count + 1 print(graph_count)
s413207918
p03805
u492447501
1565518466
Python
Python (3.4.3)
py
Runtime Error
22
3444
1031
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N-1: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True map[N-1] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N-1: graph_count = graph_count + 1 print(graph_count)
s832400804
p03805
u492447501
1565518403
Python
Python (3.4.3)
py
Runtime Error
22
3444
1016
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N-1: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N-1: graph_count = graph_count + 1 print(graph_count)
s868576848
p03805
u492447501
1565518109
Python
Python (3.4.3)
py
Runtime Error
22
3444
1015
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N or cur_node <= 0 or cur_node >= N: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True for i in range(N): if i != cur_node: dfs(i, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N-1: graph_count = graph_count + 1 print(graph_count)
s188742968
p03805
u492447501
1565516676
Python
Python (3.4.3)
py
Runtime Error
23
3444
1016
import copy def dfs(cur_node, pre_node, Node_num, map, l): #全てのノードを見たとき if Node_num == N-1 or cur_node <= 0 or cur_node >= N: return elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時 return elif map[cur_node]==True: return map[cur_node]=True dfs(cur_node+1, cur_node, Node_num+1, map, l) dfs(cur_node-1, cur_node, Node_num+1, map, l) S = input() S = list(map(int, S.split())) N = S[0] M = S[1] map = [False]*N map[0] = True lst = [] for i in range(N): lst.append([0]*N) for i in range(N): S = input() S = list(S.split()) idx1 = int(S[0]) idx2 = int(S[1]) lst[idx1-1][idx2-1] = 1 graph_count = 0 #全探索 for i in range(1, N, 1): map_copy = copy.copy(map) lst_copy = copy.copy(lst) dfs(i, 0, 0, map_copy, lst_copy) count = 0 for i in map_copy: if i == True: count = count + 1 if count == N: graph_count = graph_count + 1 print(graph_count)
s714889381
p03805
u814986259
1565459369
Python
Python (3.4.3)
py
Runtime Error
39
3064
575
N,M=map(int,input().split()) ab=[[0]*8]*8 a=[0]*M b=[0]*M reached=[0]*M for i in range(M): a[i],b[i]=map(int,input().split()) ab[a[i]-1][b[i]-1]=1 ab[b[i]-1][a[i]-1]=1 def rootCount(pos,N,reached): count=0 prev=0 finish=1 for i in range(N): if reached[i] == 0: finish=0 if finish==1: return 1 for i in range(1,N): if ab[pos][i]==0: continue if reached[i]==1: continue reached[i]=1 count+=rootCount(i,N,reached) reached[i]=0 return(count) reached[0]=1 count=rootCount(0,N,reached) print(count)
s460376125
p03805
u814986259
1565459162
Python
Python (3.4.3)
py
Runtime Error
39
3064
573
N,M=map(int,input().split()) ab=[[0]*8]*8 a=[0]*M b=[0]*M reached=[0]*M for i in range(M): a[i],b[i]=map(int,input().split()) ab[a[i]-1][b[i]-1]=1 ab[b[i]-1][a[i]-1]=1 def rootCount(pos,N,reached): count=0 prev=0 finish=1 for i in range(N): if reached[i] == 0: finish=0 if finish==1: return 1 for i in range(N): if ab[pos][i]==0: continue if reached[i]==1: continue reached[i]=1 count+=rootCount(i,N,reached) reached[i]=0 return(count) reached[0]=1 count=rootCount(0,N,reached) print(count)
s585595695
p03805
u814986259
1565453295
Python
Python (3.4.3)
py
Runtime Error
34
3064
457
N,M=map(int,input().split()) ab=[[0]*M]*M a=[0]*M b=[0]*M reached=[0]*M for i in range(M): a[i],b[i]=map(int,input().split()) ab[a[i]][b[i]]=1 ab[b[i]][a[i]]=1 def rootCount(pos,N,reached): count=0 prev=0 for i in range(N): if ab[pos][i]==0: continue if reached[i]==1: continue reached[i]=1 count+=rootCount(i,N,reached) reached[i]=0 return(count) reached[0]=1 count=rootCount(0,N,reached) print(count)
s650300560
p03805
u037430802
1564806796
Python
Python (3.4.3)
py
Runtime Error
24
3064
615
N, M = map(int, input().split()) if M == 0: print(0) exit() es = [[] for i in range(M)] for i in range(M): a, b = map(int, input().split()) a,b = a-1, b-1 es[a].append(b) es[b].append(a) def dfs(v, visited, es, cnt): #print("--------------") #print((v, visited, cnt)) if cnt == N-1: return 1 ret = 0 for i in es[v]: if visited[i] == True: continue visited[i] = True ret += dfs(i, visited, es, cnt+1) visited[i] = False return ret visited = [False] * N visited[0] = True ans = dfs(0,visited,es,0) print(ans)
s521375129
p03805
u037430802
1564806707
Python
Python (3.4.3)
py
Runtime Error
23
3064
579
N, M = map(int, input().split()) es = [[] for i in range(M)] for i in range(M): a, b = map(int, input().split()) a,b = a-1, b-1 es[a].append(b) es[b].append(a) def dfs(v, visited, es, cnt): #print("--------------") #print((v, visited, cnt)) if cnt == N-1: return 1 ret = 0 for i in es[v]: if visited[i] == True: continue visited[i] = True ret += dfs(i, visited, es, cnt+1) visited[i] = False return ret visited = [False] * N visited[0] = True ans = dfs(0,visited,es,0) print(ans)
s577735839
p03805
u214434454
1563851126
Python
Python (3.4.3)
py
Runtime Error
18
3064
703
n, m = map(int,input().split()) lis = [0 for i in range(m)] for i in range(m): lis[i] = list(map(int,input().split())) seen = [] count = 0 visited = [0 for i in range(m)] r = 0 def route(x=1): for i in range(m): if lis[i][0] == x and visited[i] == 0: visited[i] = 1 r += 1 route(lis[i][1]) visited[i] = 0 r -= 1 elif lis[i][1] == x and visited[i] == 0: visited[i] = 1 r += 1 route(lis[i][0]) visited[i] = 0 r -= 1 if r == n-1: global count count += 1 return route(1) print(count)
s938787218
p03805
u214434454
1563850751
Python
Python (3.4.3)
py
Runtime Error
17
3064
648
n, m = map(int,input().split()) lis = [0 for i in range(m)] for i in range(m): lis[i] = list(map(int,input().split())) seen = [] count = 0 def route(x=1): for i in range(m): if lis[i][0] == x and visited[i] == 0: visited[i] = 1 route(lis[i][1]) visited[i] = 0 elif lis[i][1] == x and visited[i] == 0: visited[i] = 1 route(lis[i][0]) visited[i] = 0 r = 0 for j in visited: r += j if r == n-1: global count count += 1 return route(1) print(count)
s191065026
p03805
u872887731
1563343234
Python
Python (3.4.3)
py
Runtime Error
17
3064
527
def dfs(v,N,visit_list): all_visit = True for i in range(N): if visit_list[i] == False: all_visit = False if all_visit: return 1 ret = 0 for k in range(N): if Graph[v][k] == False: continue if visit_list[k] : continue visit_list[k] = True ret += dfs(k,N,visit_list) visit_list[k] = False return ret visit_list = [False for i in range(N)] visit_list[0] = True print(dfs(0,N,visit_list))
s283573263
p03805
u872887731
1563343109
Python
Python (3.4.3)
py
Runtime Error
17
3064
735
N,M = map(int,input().split()) pat = [[int(i) for i in input().split()] for _ in range(M)] Graph = [[0 for i in range(N)] for _ in range(N)] for i,j in pat: Graph[i-1][j-1] = 1 Graph[j-1][i-1] = 1 def dfs(v,N=N,visit_list): all_visit = True for i in range(N): if visit_list[i] == False: all_visit = False if all_visit: return 1 ret = 0 for k in range(N): if Graph[v][k] == False: continue if visit_list[k] : continue visit_list[k] = True ret += dfs(k,N,visit_list) visit_list[k] = False return ret visit_list = [False for i in range(N)] visit_list[0] = True print(dfs(0,N,visit_list))
s943777224
p03805
u828766688
1562870888
Python
PyPy3 (2.4.0)
py
Runtime Error
174
38384
479
N,M = map(int,input().split()) lis = [] path = ["1"] for i in range(M): a,b = map(int,input().split()) lis.append([a,b]) for i in range(N-1): i += 1 npath = [] for p in path: for j in lis: if j[0] == int(p[-1]) and str(j[1]) not in p: npath.append(p + str(j[1])) if j[1] == int(p[-1]) and str(j[0]) not in p: npath.append(p + str(j[0])) path = npath.copy() print (len(path))
s345841670
p03805
u828766688
1562870790
Python
PyPy3 (2.4.0)
py
Runtime Error
179
38672
478
N,M = map(int,input().split()) lis = [] path = ["1"] for i in range(M): a,b = map(int,input().split()) lis.append([a,b]) for i in range(N-1): i += 1 npath = [] for p in path: for j in lis: if j[0] == int(p[-1]) and str(j[1]) not in p: npath.append(p + str(j[1])) if j[1] == int(p[-1]) and str(j[0]) not in p: npath.append(p + str(j[0])) path = npath.copy() print (len(path))
s314154158
p03805
u532966492
1562813049
Python
Python (3.4.3)
py
Runtime Error
32
8052
447
N,M=map(int,input().split()) inp=[list(map(int,input().split())) for _ in range(N)] g=[[] for _ in range(N)] [g[a-1].append(b-1) for a,b in inp] [g[b-1].append(a-1) for a,b in inp] from itertools import permutations seq=[i for i in range(N)] test=list(permutations(seq)) cnt=0 for t in test: if t[0]==0: for i in range(len(t)-1): if t[i+1] not in g[t[i]]: break else: cnt+=1 print(cnt)
s114638753
p03805
u532966492
1562812922
Python
Python (3.4.3)
py
Runtime Error
33
8052
428
N,M=map(int,input().split()) inp=[list(map(int,input().split())) for _ in range(N)] g=[[] for _ in range(N)] [g[a-1].append(b-1) for a,b in inp] [g[b-1].append(a-1) for a,b in inp] from itertools import permutations seq=[i for i in range(N)] test=list(permutations(seq)) cnt=0 for t in test: if t[0]==0: for i in range(len(t)-1): if t[i+1] not in g[t[i]]: break cnt+=1 print(cnt)
s994650153
p03805
u007550226
1562016425
Python
Python (3.4.3)
py
Runtime Error
33
3064
524
N,M = map(int,input().split()) if M == 0: print(0) else: l = [[0 for _ in range(M)] for _ in range(M)] for _ in range(M): a,b = map(int,input().split()) l[a-1][b-1] = 1 l[b-1][a-1] = 1 g = 0 def dfs(a,route): global g if len(route) == N:g += 1 else: for i in range(N): if a == i:pass else: if l[a][i] == 1 and (not i in route): dfs(i,route+[i]) dfs(0,[0]) print(g)
s016153846
p03805
u007550226
1562015744
Python
Python (3.4.3)
py
Runtime Error
34
3064
409
N,M = map(int,input().split()) l = [[0 for _ in range(M)] for _ in range(M)] for _ in range(M): a,b = map(int,input().split()) l[a-1][b-1] = 1 l[b-1][a-1] = 1 g = 0 def dfs(a,route): global g if len(route) == N:g += 1 else: for i in range(N): if a == i:pass else: if l[a][i] == 1 and (not i in route):dfs(i,route+[i]) dfs(0,[0]) print(g)
s827545259
p03805
u711539583
1561727353
Python
Python (3.4.3)
py
Runtime Error
17
3064
373
n, m = map(int, input().split()) d = {i+1 : [] for i in range(n)} for _ in range(n): a, b = map(int, input().split()) d[a].append(b) d[b].append(a) ans = 0 def go(c, rem): global ans if not len(rem): ans += 1 return for cand in d[c]: if cand in rem: i = rem.index(cand) go(cand, rem[:i] + rem[i+1:]) go(1, list(range(2, n+1))) print(ans)
s812457837
p03805
u651803486
1561681410
Python
Python (3.4.3)
py
Runtime Error
18
3064
646
N, M = map(int, input().split()) to = [[] for _ in range(N)] visited = [False] * N def dfs(v): n_visited = sum([1 if v else 0 for v in visited]) if n_visited == N: return 1 ret = 0 for u in to[v]: if not visited[u]: visited[u] = True ret += dfs(u) visited[u] = False # 最も深い点から帰ってくる道中に、始点を除く全ての点を未訪問にする => 他のパスを辿ることが可能になる return ret for _ in range(N): a, b = map(int, input().split()) to[a-1].append(b-1) to[b-1].append(a-1) visited[0] = True print(dfs(0))
s378159838
p03805
u777923818
1561434613
Python
PyPy3 (2.4.0)
py
Runtime Error
173
38256
366
def inpl(): return list(map(int, input().split())) N, M = inpl() G = [[0]*(N+1) for _ in range(N+1)] for _ in range(M): a, b = inpl() G[a][b] = 1 G[b][a] = 1 ans = 0 for X in permutations(range(2, N+1)): a = 1 for i in range(N-1): b = X[i] if G[a][b] == 0: break a = b else: ans += 1 print(ans)
s941076493
p03805
u247554097
1561389087
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38512
662
# 全域木?っていうんだっけ?でもコストは関係ないか # 適当に隣接リストでもってしてDFSする N, M = map(int, input().split()) Neighbor_list = [[] for _ in range(n)] for _ in range(M): s, t = map(int, input().split()) Neighbor_list[s-1].append(t-1) Neighbor_list[t-1].append(s-1) def dfs(cur, path): if len(path) == N: return 1 else: ret = 0 for neighbor in Neighbor_list[cur]: if neighbor not in path: next_list = path[:] next_list.append(neighbor) ret += dfs(neighbor, next_list) return ret print(dfs(0, []))
s470218041
p03805
u256031597
1561083456
Python
Python (3.4.3)
py
Runtime Error
28
3064
468
N, M = map(int, input().split()) gr = set() for i in range(N): a, b = map(int, input().split()) gr |= {(a-1,b-1),(b-1,a-1)} from itertools import permutations ans = 0 for p in permutations(range(N)): if p[0]==0: cnt = 0 cntp = 0 for i in range(N-1): cnt += 1 if (p[i],p[i+1]) in gr: cntp += 1 else: break if cnt == cntp: ans += 1 print(ans)
s798418713
p03805
u102461423
1560917620
Python
Python (3.4.3)
py
Runtime Error
27
3064
380
import itertools N,M = map(int,input().split()) edges = set() for _ in range(N): a,b = map(int,input().split()) edges.add((a,b)) edges.add((b,a)) answer = 0 for p in itertools.permutations(range(1,N+1)): if p[0] != 1: continue bl = True for i in range(N-1): if (p[i], p[i+1]) not in edges: bl = False break if bl: answer += 1 print(answer)
s425996575
p03805
u580904613
1560822702
Python
Python (3.4.3)
py
Runtime Error
17
3064
491
n, m = map(int, input().split()) adj_matrix = [[0] * n for _ in range(N)] for i in range(m): a, b = map(int, input().split()) adj_matrix[a-1][b-1] = 1 adj_matrix[b-1][a-1] = 1 def dfs(v, used): if not False in used: return 1 ans = 0 for i in range(n): if not adj_matrix[v][i]: continue if used[i]: continue used[i] = True ans += dfs(i, used) used[i] = False return ans used = [False] * n used[0] = True print(dfs(0, used))
s840061153
p03805
u672494157
1560632129
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38256
1039
import sys from collections import deque sys.setrecursionlimit(4100000) def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def solve(N, M, inputs): relations = {} visited_all = (2 ** N) - 1 for i in range(1, N + 1): relations[i] = [] for i in inputs: [parent, child] = string_to_int(i) relations[parent].append(child) relations[child].append(parent) routes = 0 queue = deque([[1, 0]]) while len(queue) > 0: [node, visited] = queue.popleft() if visited & (1 << (node - 1)) != 0: continue visited = visited + (1 << (node - 1)) if visited == visited_all: routes += 1 continue for next in relations[node]: queue.append([next, visited]) return routes def string_to_int(string): return list(map(lambda x: int(x), string.split())) if __name__ == "__main__": [N, M] = string_to_int(input()) ret = solve(inputs(M)) print(ret)
s026617342
p03805
u977193988
1560547222
Python
Python (3.4.3)
py
Runtime Error
26
3064
519
import sys sys.setrecursionlimit(10000) n,m=map(int,input().split()) bra=[set() for _ in range(m)] for i in range(m): a,b=map(int,input().split()) bra[a-1].add(b-1) bra[b-1].add(a-1) visit=[1]+[0]*(n-1) #print(bra) cnt=[] def dfs(a,visit): if visit==[1]*n: cnt.append(1) return else: for e in bra[a]: if visit[e]==0: visit[e]=1 # print(visit) dfs(e,visit) visit[e]=0 dfs(0,visit) print(len(cnt))
s638746561
p03805
u977193988
1560545787
Python
Python (3.4.3)
py
Runtime Error
27
3064
519
import sys sys.setrecursionlimit(10000) n,m=map(int,input().split()) bra=[set() for _ in range(m)] for i in range(m): a,b=map(int,input().split()) bra[a-1].add(b-1) bra[b-1].add(a-1) visit=[1]+[0]*(n-1) #print(bra) cnt=[] def dfs(a,visit): if visit==[1]*n: cnt.append(1) return else: for e in bra[a]: if visit[e]==0: visit[e]=1 # print(visit) dfs(e,visit) visit[e]=0 dfs(0,visit) print(sum(cnt))
s722503739
p03805
u977193988
1560545660
Python
Python (3.4.3)
py
Runtime Error
26
3064
494
n,m=map(int,input().split()) bra=[set() for _ in range(m)] for i in range(m): a,b=map(int,input().split()) bra[a-1].add(b-1) bra[b-1].add(a-1) visit=[1]+[0]*(n-1) #print(bra) cnt=[] def dfs(a,visit): if visit==[1]*n: cnt.append(1) return else: for e in bra[a]: if visit[e]==0: visit[e]=1 # print(visit) dfs(e,visit) visit[e]=0 dfs(0,visit) print(sum(cnt))
s260524089
p03805
u416773418
1560391329
Python
Python (3.4.3)
py
Runtime Error
2209
1707424
498
import itertools n,m=map(int,input().split()) lst=[] for i in range(m): lst+=[list(map(int,input().split()))] pair=[[0]*n for i in range(n)] for i,j in lst: pair[i-1][j-1]=1 pair[j-1][i-1]=1 def keiro(a): count=0 for i in range(n-1): if pair[a[i]-1][a[i+1]-1]==0: break else: count+=1 return count cn=0 b=[i for i in range(2,m+1)] for i in list(itertools.permutations(b)): a=[1]+list(i) if keiro(a)==1: cn+=1 print(cn)
s975307603
p03805
u620219777
1559880472
Python
Python (3.4.3)
py
Runtime Error
37
3064
682
N, M = map(int, input().split()) graph = [] visited = [] def dfs(v, N, visited): all_visited = True for i in range(N): if(visited[i]==False): all_visited = False if (all_visited): return 1 ret = 0 for i in range(N): if(graph[v][i]==False): continue if(visited[i]): continue visited[i] = True ret += dfs(i, N, visited) visited[i] = False return ret for i in range(M): graph.append([False] * 8) for i in range(N): visited.append(False) for i in range(M): A, B = map(int, input().split()) graph[A-1][B-1] = graph[B-1][A-1] = True visited[0] = True print(dfs(0, N, visited))
s048574096
p03805
u879870653
1559834386
Python
Python (3.4.3)
py
Runtime Error
17
3064
556
N,M = map(int,input().split()) L = [[] for i in range(N)] for i in range(M) : a,b = map(int,input().split()) a -= 1 b -= 1 L[a].append(b) L[b].append(a) P = permutations([0] + [i for i in range(1,N)]) ans = 0 for perm in P : visited = [0 for i in range(N)] visited[0] = 1 for i in range(N-1) : if perm[i+1] not in L[perm[i]] : break if visited[perm[i+1]] : break visited[perm[i+1]] = 1 if sum(visited) == N : ans += 1 print(ans)
s668172787
p03805
u838644735
1559797070
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38384
631
l = input().split() N = int(l[0]) M = int(l[1]) A = [] B = [] C = [[] for i in range(N)] for i in range(M): l = input().split() a = int(l[0]) - 1 b = int(l[1]) - 1 A.append(a) B.append(b) C[a].append(b) C[b].append(a) # print(N, M, A, B, C) def visit(cur, ans, visited): # print('cur={}, ans={}'.format(cur, ans)) visited.append(cur) if cur == N - 1: # print('goal') return ans + 1 for next in C[cur]: if next not in visited: return visit(next, ans, visited) ans = 0 for next in C[0]: visited = [] ans += visit(0, 0, visited) print(ans)
s923784408
p03805
u969190727
1558749589
Python
Python (3.4.3)
py
Runtime Error
44
3064
439
import itertools n,m=map(int,input().split()) A=[] for i in range(n): a,b=map(int,input().split()) A.append([a,b]) N=[int(i+2) for i in range(n-1)] def f(list,n): path=0 if [1,list[0]] in A: path+=1 for i in range(1,n-1): if [list[i],list[i-1]] in A or [list[i-1],list[i]] in A: path+=1 if path==n-1: return 1 else: return 0 ans=0 for p in itertools.permutations(N,n-1): ans+=f(list(p),n) print(ans)
s796380501
p03805
u039360403
1558432424
Python
Python (3.4.3)
py
Runtime Error
39
8052
306
import itertools N,M=map(int,input().split()) ab=list(list(map(int,input().split())) for _ in range(N)) l=list(l for l in range(1,N+1)) numlist=list(itertools.permutations(l)) ans=0 for I in numlist: x=0 if I[0]==1 and all(sorted([I[j],I[j+1]]) in ab for j in range(N-1)): ans+=1 print(ans)
s885173146
p03805
u500944229
1558246317
Python
Python (3.4.3)
py
Runtime Error
18
3064
494
n,m = map(int,input()) path = [map(int,input()) for x in range(m)] table = [[] for x in range(n)] for x in path: table[int(x[0])-1].append(int(x[1])-1) table[int(x[1])-1].append(int(x[0])-1) import itertools count = 0 for z in itertools.permutations(range(0,n)): if z[0] == 0: print(z) for y in range(len(z)-1): if z[y+1] in table[z[y]]: continue else: count -= 1 break count += 1
s328568564
p03805
u785578220
1558129049
Python
Python (3.4.3)
py
Runtime Error
17
2940
271
from itertools import permutations n,m=map(int,input().split()) path=set() for _ in range(m): u,v=map(int,input().split()) path|={(u-1,v-1),(v-1,u-1)} s = 0 for i in permutations(range(n)): s+=(all((h,j) in path for h,j in zip(i[1:],i))) if i[0] ==0 print(s)
s339701210
p03805
u785578220
1558128313
Python
Python (3.4.3)
py
Runtime Error
18
3060
292
######### #thiking Face from itertools import permutations n,m=map(int,input().split()) path=set() for _ in range(m): u,v=map(int,input().split()) path|={(u-1,v-1),(v-1,u-1)} print(sum(all((u,v) in es for u,v in zip(p,p[1:])) for p in permutations(range(n)) if p[0]==0))
s403240898
p03805
u785578220
1558128153
Python
Python (3.4.3)
py
Runtime Error
18
3060
296
########### ######### #thiking Face from itertools import permutations n,m=map(int,input().split()) path=set() for _ in range(m): u,v=map(int,input().split()) path|={(u-1,v-1),(v-1,u-1)} print(sum(all((u,v) in es for u,v in zip([0]+p,p)) for p in permutations(range(1,n))))
s529487614
p03805
u172386990
1557897336
Python
Python (3.4.3)
py
Runtime Error
251
17124
1060
import numpy as np N, M = map(int, input().split()) Adj_matrix = np.zeros((N, N)) for _ in range(N): a, b = map(int, input().split()) Adj_matrix[a - 1, b - 1] += 1 Adj_matrix[b - 1, a - 1] += 1 def initialize(): explored_list = np.zeros((N, 1)) return explored_list def is_move(vertex, explored_list, Adj_martrix): for i in range(len(explored_list)): if explored_list[i] == 0 and Adj_martrix[vertex - 1, i] == 1: return True return False import copy g_count = 0 def graph_exp(vertex, explored_list, Adj_matrix): global g_count explored_list[vertex - 1] += 1 # Recursive End if not is_move(vertex, explored_list, Adj_matrix): g_count += all(explored_list) return 0 # Recursive Call for i in range(len(explored_list)): if explored_list[i] == 0 and Adj_matrix[vertex - 1, i] == 1: graph_exp(i + 1, copy.copy(explored_list), Adj_matrix) explored_list = initialize() graph_exp(1, explored_list, Adj_matrix) print(g_count)
s226863621
p03805
u392220578
1557031214
Python
Python (3.4.3)
py
Runtime Error
17
3060
298
import itertools n, m = [int(x) for x in input().split()] edges = set(tuple(int(x) for x in input().split()) for _ in range(m)) print(sum(1 if all(p in edges or tuple(reversed(p)) in edges for p in [(1, path[0]), *zip(path, path[1:])]) else 0 for path in itertools.permutations(range(2, n + 1))))