problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p03805 | u101350975 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nn, m = map(int, input().split())\npath = [[False] * n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\nans = 0\nfor i itertools.permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if j == n - 1:\n ans += 1\n break\n if not path[i[j]][i[j+1]]:\n break\nprint(ans)\n', 'import itertools\nn, m = map(int, input().split())\npath = [[False] * n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\nans = 0\nfor i in itertools.permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if j == n - 1:\n ans += 1\n break\n if not path[i[j]][i[j+1]]:\n break\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s915390436', 's649298485'] | [8960.0, 9212.0] | [21.0, 38.0] | [453, 456] |
p03805 | u102655885 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from collections import defaultdict\nn, m = map(lambda x: int(x), input().split())\n\nlinks = defaultdict(set)\n\nfor _ in range(m):\n a, b = map(lambda x: int(x), input().split())\n links[a].add(b)\n links[b].add(a)\n \npath_counter = 0\n \ndef path_patterns_number(current_node, remaining_nodes):#, remaining_links):\n# print(current_node, remaining_nodes)\n if len(remaining_nodes) == 0:\n return 1\n \n patterns = 0\n \n for next_node in (links[current_node] & remaining_nodes):\n# remaining_links_copy = remaining_links.copy()\n\n patterns += path_patterns_number(\n next_node,\n remaining_nodes.copy() - {next_node}\n# remaining_links_copy\n )\n \n return patterns\n \npath_patterns_number(1, set(range(2,n+1)))#, links)', 'from collections import defaultdict\nn, m = map(lambda x: int(x), input().split())\n\nlinks = defaultdict(set)\n\nfor _ in range(m):\n a, b = map(lambda x: int(x), input().split())\n links[a].add(b)\n links[b].add(a)\n \npath_counter = 0\n \ndef path_patterns_number(current_node, remaining_nodes):#, remaining_links):\n# print(current_node, remaining_nodes)\n if len(remaining_nodes) == 0:\n return 1\n \n patterns = 0\n \n for next_node in (links[current_node] & remaining_nodes):\n# remaining_links_copy = remaining_links.copy()\n\n patterns += path_patterns_number(\n next_node,\n remaining_nodes.copy() - {next_node}\n# remaining_links_copy\n )\n \n return patterns\n \nprint(path_patterns_number(1, set(range(2,n+1)))#, links))', 'from collections import defaultdict', 'import numpy', 'from collections import defaultdict\nn, m = map(lambda x: int(x), input().split())\n\nlinks = defaultdict(set)\n\nfor _ in range(m):\n a, b = map(lambda x: int(x), input().split())\n links[a].add(b)\n links[b].add(a)\n \npath_counter = 0\n \ndef path_patterns_number(current_node, remaining_nodes):#, remaining_links):\n if len(remaining_nodes) == 0:\n return 1\n \n patterns = 0\n \n for next_node in (links[current_node] & remaining_nodes):\n# remaining_links_copy = remaining_links.copy()\n\n patterns += path_patterns_number(\n next_node,\n remaining_nodes.copy() - {next_node}\n# remaining_links_copy\n )\n \n return patterns\n \nprint(path_patterns_number(1, set(range(2,n+1))))'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s547126462', 's747462476', 's904741739', 's913488582', 's280278451'] | [9228.0, 9068.0, 9392.0, 26964.0, 9400.0] | [38.0, 24.0, 33.0, 116.0, 40.0] | [924, 931, 35, 12, 879] |
p03805 | u103902792 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m = map(int,input().split())\ngraph = {i+1:[] for i in range(n)}\nfor _ in range(m):\n a,b = map(int,input(),split())\n graph[a].append(b)\n graph[b].append(a)\n\ncount = 0\ndef func(path,p):\n if len(path) == n:\n count += 1\n return\n for i in graph[p]:\n if i in path:\n continue\n func(path+[i],i)\nprint(count)', '#dfs\nn,m = map(int,input().split())\ngraph = {i+1:[] for i in range(n)}\nfor _ in range(m):\n a,b = map(int,input().split())\n graph[a].append(b)\n graph[b].append(a)\n\ndef func(path,p,count):\n if len(path) == n:\n return count + 1\n for i in graph[p]:\n if i in path:\n continue\n count = func(path+[i],i,count)\n return count\nprint(func([1],1,0))\n\n\n'] | ['Runtime Error', 'Accepted'] | ['s757295658', 's869367241'] | [3064.0, 3064.0] | [20.0, 27.0] | [323, 359] |
p03805 | u112317104 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(N)]\n\nvisited = [False] * N\nvisited[0] = True\nd = {}\nfor a, b in A:\n d.setdefault(a, []).append(b)\n d.setdefault(b, []).append(a)\n\nl = sorted(d.items())\n\n# print(d)\ndef dfs(v, c):\n if visited[v-1]: return 0\n visited[v-1] = True\n if False not in visited:\n c += 1\n \n # print(visited, False not in visited, c)\n \n \n \n for next_v in d[v]:\n c += dfs(next_v, c)\n \n return c\n\nc = 0\nans = 0\nfor i in l[0][1]:\n ans += dfs(i, c)\n \nprint(ans)\n\n', 'N, M = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(M)]\n\nvisited = [False] * N\nvisited[0] = True\nd = {}\nfor a, b in A:\n d.setdefault(a, []).append(b)\n d.setdefault(b, []).append(a)\n\nl = sorted(d.items())\n\n# print(d)\ndef dfs(v, c):\n if visited[v-1]: return 0\n visited[v-1] = True\n if False not in visited:\n c += 1\n \n # print(visited, False not in visited, c)\n \n \n \n for next_v in d[v]:\n c += dfs(next_v, c)\n \n return c\n\nc = 0\nans = 0\nfor i in l[0][1]:\n ans += dfs(i, c)\n \nprint(ans)\n\n', 'N, M = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(M)]\n\nvisited = [False] * N\nvisited[0] = True\nd = {}\nfor a, b in A:\n d.setdefault(b-1, []).append(a-1)\n d.setdefault(a-1, []).append(b-1)\n\nl = sorted(d.items())\n\ndef dfs(v, seen):\n if False not in seen: return 1\n \n c = 0\n for i in d[v]:\n if (seen[i]): continue\n seen[i] = True\n c += dfs(i, seen)\n seen[i] = False\n return c\n \nprint(dfs(0, visited))\n\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s882828688', 's934634038', 's984487045'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 23.0] | [595, 595, 485] |
p03805 | u119655368 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nl = [list(map(int, input().split())) for i in range(m)]\nr = [[] for i in range(n + 1)]\nans = 0\nfor i in range(m):\n r[l[i][0]].append(l[i][1])\n r[l[i][1]].append(l[i][0])\np = []\nfor i in range(n):\n p.append(i + 1)\np = list(itertools.permutations(p))\nfor i in range(len(p)):\n check = True\n t = list(p[i])\n if t[0] != 1:\n check = False\n for j in range(len(t)-1):\n if not t[j + 1] in r[t[j]]:\n check = False\n if check:\n ans += 1\nprint(ans)', 'import itertools\n\nn, m = map(int, input().split())\nl = [list(map(int, input().split())) for i in range(m)]\nr = [[] for i in range(n + 1)]\nans = 0\nfor i in range(m):\n r[l[i][0]].append(l[i][1])\n r[l[i][1]].append(l[i][0])\np = "2345678"[:n-1]\np = list(itertools.permutations(p))\nfor i in range(len(p)):\n check = True\n t = "1" + "".join(p[i])\n for j in range(len(t)-1):\n if not int(t[j + 1]) in r[int(t[j])]:\n check = False\n if check:\n ans += 1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s329791591', 's609909644'] | [3064.0, 3572.0] | [18.0, 46.0] | [524, 495] |
p03805 | u125205981 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\ndef path(n):\n l = len(n)\n i = 0\n while i < l - 1:\n a = n[i]\n b = n[i + 1]\n\n if a < b:\n c = (a, b)\n else:\n c = (b, a)\n\n for m in C:\n if m == c:\n break\n else:\n return False\n i += 1\n return True\n\nN, M = map(int, input().split())\nC = []\ni = 0\nwhile i < N:\n C += [tuple(map(int, input().split()))]\n i += 1\n\ni = 0\nl = range(1, N + 1)\nfor n in itertools.permutations(l, N):\n print(n)\n if n[0] != 1:\n break\n if path(n) == True:\n i += 1\nprint(str(i))', 'import itertools\n\ndef path(n):\n l = len(n)\n i = 0\n while i < l - 1:\n a = n[i]\n b = n[i + 1]\n\n if a < b:\n c = (a, b)\n else:\n c = (b, a)\n\n for m in C:\n if m == c:\n break\n else:\n return False\n i += 1\n return True\n\nN, M = map(int, input().split())\nC = []\ni = 0\nwhile i < M:\n C += [tuple(map(int, input().split()))]\n i += 1\n\ni = 0\nl = range(1, N + 1)\nfor n in itertools.permutations(l, N):\n if n[0] != 1:\n break\n if path(n) == True:\n i += 1\nprint(str(i))'] | ['Runtime Error', 'Accepted'] | ['s146658656', 's917982191'] | [3188.0, 3064.0] | [34.0, 54.0] | [608, 595] |
p03805 | u127499732 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["def main():\n _, __ = map(int, input().split())\n ___ = [[] for _ in range(_)]\n for _ in range(__):\n ____, _____ = map(lambda ______: int(_____) - 1, input().split())\n ___[____].append(_____)\n ___[_____].append(____)\n\n _______ = [False] * _\n ________ = ___________(0, ___, _______, 0)\n\n print(________)\n\n\ndef ___________(_____, ___, _______, _________):\n _______[_____] = True\n if all(_______):\n return _________ + 1\n\n for __________ in ___[_____]:\n if _______[__________]:\n continue\n _________ = ___________(__________, ___, _______, _________)\n _______[__________] = False\n\n return _________\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n お寿司, 食べたい = map(int, input().split())\n 築地 = [[] for _ in range(お寿司)]\n for _ in range(食べたい):\n 鮪, 蛸 = map(lambda x: int(x) - 1, input().split())\n 築地[鮪].append(蛸)\n 築地[蛸].append(鮪)\n\n やってるかい = [False] * お寿司\n 寿司くいねぇ = おなかすいた(0, 築地, やってるかい, 0)\n\n print(寿司くいねぇ)\n\n\ndef おなかすいた(市場, 築地, やってるかい, お勘定):\n やってるかい[市場] = True\n if all(やってるかい):\n return お勘定 + 1\n\n for 豪遊 in 築地[市場]:\n if やってるかい[豪遊]:\n continue\n お勘定 = おなかすいた(豪遊, 築地, やってるかい, お勘定)\n やってるかい[豪遊] = False\n\n return お勘定\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s493526910', 's471630725'] | [3064.0, 3320.0] | [18.0, 24.0] | [722, 885] |
p03805 | u131881594 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools as it\nn,m=map(int,input().split())\npath={[] for _ in range(m)}\nfor i in range(m): path[i]=list(map(int,input().split()))\nls=list(it.permutations(range(1,n+1)))\ncnt=0\nfor l in ls:\n if l[0]==1: break\n for i in range(n-1):\n if [i,i+1] in path: cnt+=1\nprint(cnt)', 'import itertools as it\n\nn,m=map(int,input().split())\npath=[]\nfor i in range(m): path.append(list(map(int,input().split())))\nls=list(it.permutations(range(1,n+1)))\ncnt=0\nfor l in ls:\n if l[0]!=1: break\n flag=1\n for i in range(n-1):\n if ([l[i],l[i+1]] not in path) and ([l[i+1],l[i]] not in path):\n flag=0\n break\n if flag: cnt+=1\nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s320464368', 's200997795'] | [9208.0, 13900.0] | [23.0, 69.0] | [288, 379] |
p03805 | u134520518 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn, m = map(int, input().split())\n\ntu = [[] for j in range(n+1)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n tu[a].append(b)\n tu[b].append(a)\n\nna = [i for i in range(2,n+1)]\nans = 0\n\n\nprint(permutations(na))\nfor nara in permutations(na):\n st = 1\n f = True\n for i in range(n-1):\n if not nara[i] in tu[st]:\n f = False\n st = nara[i]\n if f == True:\n\n ans += 1\n\nprint(ans)', 'from itertools import permutations\n\nn, m = map(int, input().split())\n\ntu = [[] for j in range(n+1)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n tu[a].append(b)\n tu[b].append(a)\n\nna = [i for i in range(2,n+1)]\nans = 0\n\nfor nara in permutations(na):\n st = 1\n f = True\n for i in range(n-1):\n if not nara[i] in tu[st]:\n f = False\n st = nara[i]\n if f == True:\n ans += 1\n\n\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s350434616', 's678526588'] | [3064.0, 3064.0] | [30.0, 30.0] | [466, 442] |
p03805 | u139112865 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['#054_C\nfrom itertools import permutations\nn,m=map(int,input().split())\nedges=[[False for _ in range(n)] for _ in range(n)]\nfor _ in range(m):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n edges[a][b]=edges[b][sa]=True\n\nans=0\nfor l in permutations(range(1,n),n-1):\n l=[0]+list(l)\n if all(edges[l[i]][l[i+1]] for i in range(n-1)):\n ans+=1\nprint(ans)', '#054_C\nfrom itertools import permutations\nn,m=map(int,input().split())\nedges=[[False for _ in range(n)] for _ in range(n)]\nfor _ in range(m):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n edges[a][b]=edges[b][a]=True\n\nans=0\nfor l in permutations(range(1,n),n-1):\n l=[0]+list(l)\n if all(edges[l[i]][l[i+1]] for i in range(n-1)):\n ans+=1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s889864554', 's177958250'] | [3064.0, 3064.0] | [17.0, 29.0] | [367, 366] |
p03805 | u140251125 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['# input\nN, M = map(int, input().split())\nG = [list(map(int, input().split())) for _ in range(M)]\nedges = [set() for _ in range(N)]\n\nfor a, b in G:\n edges[a - 1].add((b - 1, 1))\n edges[b - 1].add((a - 1, 1))\n\ndef dfs(start, edges, path):\n path.append(start)\n if len(path) == n:\n path.pop()\n return 1\n ans = 0\n for u in edges[start]:\n if u in path:\n continue\n ans += dfs(u, path)\n path.pop()\n return ans \n\nprint(dfs(0, []))\n', '# input\nN, M = map(int, input().split())\nG = [list(map(int, input().split())) for _ in range(M)]\nedges = [set() for _ in range(N)]\n\nfor a, b in G:\n edges[a - 1].add(b - 1)\n edges[b - 1].add(a - 1)\n\ndef dfs(start, edges, path):\n path.append(start)\n if len(path) == N:\n path.pop()\n return 1\n ans = 0\n for u in edges[start]:\n if u in path:\n continue\n ans += dfs(u, edges, path)\n path.pop()\n return ans \n\nprint(dfs(0, edges, []))\n'] | ['Runtime Error', 'Accepted'] | ['s657224927', 's906310852'] | [3188.0, 3064.0] | [18.0, 27.0] | [488, 492] |
p03805 | u143492911 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nedges=[[] for _ in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n edges[a-1]+=[b-1]\n edges[b-1]+=[a-1]\nvis=[1]+[0]*(n-1)\n\ndef dfs(v):\n if vis==[1]*n:\n return 1\n count=0\n for i in edges[v]:\n if vis[i]==0:\n vis[i]=1\n count+=dfs(i)\n vis[i]=0\n else:\n return count\nprint(dfs(0))', 'import numpy as np\nn,m=map(int,input().split())\nif m==0:\n print(0)\n exit()\nans=[[] for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n ans[a-1].append((b-1))\n ans[b-1].append((a-1))\nv=[]\ndef dfs(now,visited=[]):\n global v\n if len(visited)==n:\n v.append([visited])\n return\n for j in ans[now]:\n for j not in visited:\n dfs(j,visited+[j])\ndfs(0,[0])\nprint(len(v))', 'n,m=map(int,input().split())\nif m==0:\n print(0)\n exit()\nans=[[] for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n ans[a-1].append((b-1))\n ans[b-1].append((a-1))\nv=[]\ndef dfs(now,visited=[]):\n global v\n if len(visited)==n:\n v.append([visited])\n return\n for j in ans[now]:\n if j not in visited:\n dfs(j,visited+[j])\nprint(v)\ndfs(0,[0])\nprint(len(v))\n', 'def dfs(now,depth):\n if vis[now]:\n return 0\n if depth==n:\n return 1\n vis[now]=1\n ans=0\n for i in range(n):\n if graph[now][i]:\n ans+=dfs(i,depth+1)\n vis[now]=0\n return ans\nn,m=map(int,input().split())\nedge=[[int(i)for i in input().split()]for i in range(m)]\ngraph=[[0 for i in range(n)] for i in range(n)]\nvis=[0]*n\nfor i in range(m):\n graph[edge[i][0]-1][edge[i][1]-1]=1\n graph[edge[i][1]-1][edge[i][0]-1]=1\nprint(dfs(0,1))\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s418173602', 's971961629', 's982173634', 's226732407'] | [3064.0, 3060.0, 4212.0, 3064.0] | [24.0, 17.0, 31.0, 36.0] | [398, 432, 450, 483] |
p03805 | u151625340 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\ndict = {}\nfor m in range(M):\n a,b = map(int,input().split())\n if a in dict:\n dict[a].append(b)\n else:\n dict[a] = [b]\n if b in dict:\n dict[b].append(a)\n else:\n dict[b] = [a]\nans = 0\nl = [0 for i in range(N+1)]\nl[1] = 1\ndef dfs(l,now):\n global ans\n if sum(l) == N:\n ans += 1\n return(0)\n for i in dict[now]:\n print(i)\n if l[i] == 0:\n l[i] += 1\n now = i\n dfs(l,now)\n l[i] -= 1\n else:\n continue\ndfs(l,1)\nprint(ans)\n', 'N,M = map(int,input().split())\ndict = {}\nfor m in range(M):\n a,b = map(int,input().split())\n if a in dict:\n dict[a].append(b)\n else:\n dict[a] = [b]\n if b in dict:\n dict[b].append(a)\n else:\n dict[b] = [a]\nans = 0\nl = [0 for i in range(N+1)]\nl[1] = 1\ndef dfs(now):\n global l\n global ans\n if sum(l) == N:\n ans += 1\n return(0)\n for i in dict[now]:\n if l[i] == 0:\n l[i] += 1\n now = i\n dfs(l,now)\n l[i] -= 1\n else:\n continue\ndfs(l,1)\nprint(ans)\n', 'N,M = map(int,input().split())\ndict = {}\nfor m in range(M):\n a,b = map(int,input().split())\n if a in dict:\n dict[a].append(b)\n else:\n dict[a] = [b]\n if b in dict:\n dict[b].append(a)\n else:\n dict[b] = [a]\nans = 0\nl = [0 for i in range(N+1)]\nl[1] = 1\ndef dfs(l,now):\n global ans\n if sum(l) == N:\n ans += 1\n return(0)\n for i in dict[now]:\n if l[i] == 0:\n l[i] += 1\n now = i\n dfs(l,now)\n l[i] -= 1\n else:\n continue\ndfs(l,1)\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s696055502', 's809728280', 's094276676'] | [3824.0, 3188.0, 3064.0] | [58.0, 18.0, 27.0] | [583, 577, 565] |
p03805 | u156163787 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn,m=map(int,input().split())\nes=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n es|={(u-1,v-1),(v-1,u-1)}\n\nprint(sum(all((u,v) in es for u,v in zip(p,p[1:]))\n for p in permutations(range(n)) if p[0]))\n', 'from itertools import permutations\n\nn,m=map(int,input().split())\nes=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n es|={(u-1,v-1),(v-1,u-1)}\n\nprint(sum(all((u,v) in es for u,v in zip(p,p[1:]))\n for p in permutations(range(n)) if p[0]==0))\n'] | ['Wrong Answer', 'Accepted'] | ['s157034216', 's271937091'] | [3060.0, 3060.0] | [80.0, 29.0] | [260, 263] |
p03805 | u166201488 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nN, M = map(int, input().split())\np = [list(map(int, input().split())) for i in range(M)]\nv = list(map(list, itertools.permutations(range(1,N+1), N)))\ncnt = 0\nfor i in range(len(v)):\n for j in range(N-1):\n #print((i,j))\n \n if v[i][j:j+2] in p:\n cnt += 1\nprint(int(cnt/2))', 'import itertools\nN, M = map(int, input().split())\np = [list(map(int, input().split())) for i in range(M)]\nv = list(map(list, itertools.permutations(range(2,N+1), N-1)))\ncnt = 0\nfor i in range(len(v)):\n\tvit = True\n v_i = [1]+v[i]\n for j in range(N-1):\n if sorted(v_i[j:j+2]) not in p:\n vit = False\n if vit:\n cnt += 1\nprint(cnt)', 'N, M = map(int, input().split())\np = [list(map(int, input().split())) for i in range(M)]\nimport itertools\nv = list(map(list, itertools.permutations(range(2,N+1), N-1)))\ncnt = 0\nfor i in range(len(v)):\n vit = True\n v_i = [1]+v[i]\n for j in range(N-1):\n if sorted(v_i[j:j+2]) not in p:\n vit = False\n if vit:\n cnt += 1\nprint(cnt)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s603733274', 's791786160', 's460755173'] | [12276.0, 3060.0, 3828.0] | [285.0, 18.0, 56.0] | [341, 360, 363] |
p03805 | u183896397 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = (int(i) for i in input().split())\nK = []\nfor i in range(M):\n J = [int(i) for i in input().split()]\n J.sort()\n K.append(J)\n\n\nvertex = []\nfor i in range(N-1):\n vertex.append(i+2)\n\nX = list(itertools.permutations(vertex))\n\n\nans = 0\nfor i in X:\n start = 1\n localcount = 0\n for j in i:\n tmp = [start,j]\n tmp.sort()\n if tmp in K == False:\n break \n else:\n localcount += 1\n start = j\n \n if localcount == N-1:\n ans += 1\n\nprint(ans)', 'N,M = (int(i) for i in input().split())\nK = []\nfor i in range(M):\n J = [int(i) for i in input().split()]\n J.sort()\n K.append(J)\n\n\nvertex = []\nfor i in range(N-1):\n vertex.append(i+2)\n\nX = list(itertools.permutations(vertex))\n\n\nans = 0\nfor i in X:\n start = 1\n localcount = 0\n for j in i:\n tmp = [start,j]\n tmp.sort()\n if tmp in K: \n localcount += 1 \n start = j\n \n if localcount == N-1:\n ans += 1\n\nprint(ans) ', 'import itertools\nN,M = (int(i) for i in input().split())\nK = []\nfor i in range(M):\n J = [int(i) for i in input().split()]\n J.sort()\n K.append(J)\n\n\nvertex = []\nfor i in range(N-1):\n vertex.append(i+2)\n\nX = list(itertools.permutations(vertex))\n\n\nans = 0\nfor i in X:\n start = 1\n localcount = 0\n for j in i:\n tmp = [start,j]\n tmp.sort()\n if tmp in K: \n localcount += 1 \n start = j\n \n if localcount == N-1:\n ans += 1\n\nprint(ans) '] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s453090378', 's589965427', 's041521721'] | [3064.0, 3064.0, 3572.0] | [17.0, 18.0, 50.0] | [627, 587, 603] |
p03805 | u186838327 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nl = [[] for _ in range(m)]\nfor i in range(m):\n a, b = map(int, input().split())\n l[a-1].append(b-1)\n l[b-1].append(a-1)\n\nimport itertools\nans = 0\nfor p in itertools.permutations(range(n)):\n if p[0] == 0:\n flag = 1\n for i in range(n-1):\n if p[i+1] in l[p[i]]:\n pass\n else:\n flag = 0\n if flag == 1:\n ans += 1\nprint(ans)', 'n, m = map(int, input().split())\nl = [[] for _ in range(m)]\nfor i in range(m):\n a, b = map(int, input().split())\n l[a-1].append(b-1)\n l[b-1].append(a-1)\n\nimport itertools\nans = 0\nfor p in itertools.permutations(range(n)):\n if p[0] == 0:\n flag = 1\n else:\n flag = 0\n for i in range(n-1):\n if not p[i+1] in l[p[i]]:\n flag = 0\n if flag == 1:\n ans += 1\nprint(ans)\n', 'n, m = map(int, input().split())\ng = [[] for _ in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n g[a].append(b)\n g[b].append(a)\n\ndp = [[0]*n for i in range(2**n)]\ndp[1][0] = 1\n\nfor s in range(2**n):\n for v in range(n):\n if (s >> v) & 1:\n \n t = s ^ (1 << v)\n for u in g[v]:\n if (t >> u) & 1:\n dp[s][v] += dp[t][u]\n#print(dp)\nans = 0\nfor v in range(n):\n ans += dp[-1][v]\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s046744504', 's917491591', 's593071237'] | [3188.0, 3064.0, 9020.0] | [37.0, 94.0, 30.0] | [433, 434, 518] |
p03805 | u191829404 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from collections import defaultdict\nfrom collections import deque\n\nN, M = map(int, input().split())\n\ngraph = defaultdict(list)\nedges = []\n\n\nfor _ in range(M):\n a, b = map(int, input().split())\n graph[a].append(b)\n graph[b].append(a)\n edges.append((a, b))\n\nans = 0\n\ndef dfs(graph, node_start, visited):\n global ans\n print(visited)\n if len(set(visited)) == len(set(graph)):\n ans += 1\n return\n for node_end in graph[node_start]:\n \n if node_end not in visited:\n dfs(graph, node_end, visited + [node_end])\n return\n\ndfs(graph, 1, [1])\nprint(ans)\n', 'from collections import defaultdict\nfrom collections import deque\n\nN, M = map(int, input().split())\n\ngraph = defaultdict(list)\nedges = []\n\n\nfor _ in range(M):\n a, b = map(int, input().split())\n graph[a].append(b)\n graph[b].append(a)\n edges.append((a, b))\n\nans = 0\n\ndef dfs(graph, node_start, visited):\n global ans\n if len(set(visited)) == len(set(graph)):\n ans += 1\n return\n for node_end in graph[node_start]:\n \n if node_end not in visited:\n dfs(graph, node_end, visited + [node_end])\n return\n\ndfs(graph, 1, [1])\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s967081405', 's018737024'] | [3692.0, 3316.0] | [65.0, 44.0] | [661, 642] |
p03805 | u201802797 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nnim,mike = list(map(int,input().split()))\narray = [list(map(int,input().split())) for i in range(mike)]\ncounter = 0\nfor i in permutations(range(1,nim+1)):\n boo = True\n if i[0]==1:\n for i in range(nim-1):\n if sorted([i[i],i[i+1]]) not in array:\n boo = False\n if boo:\n counter+=1\nprint(counter)', '# solution\nimport io\nimport math\nimport itertools as it\n\nnim,mike = map(int, input().split())\n\narrat = []\n\nfor i in range(mike):\n a,b = map(int, input().split())\n arrat.append([a,b])\n\nper = it.permutations(range(2,nim+1),nim-1)\n\nresult = 0\n\nfor pe in per:\n Flag = True\n pe = list(pe)\n pe.insert(0,1)\n for i in range(len(pe)-1):\n if [pe[i],pe[i+1]] not in arrat and [pe[i+1],pe[i]] not in arrat:\n Flag = False\n break\n if Flag == True:\n result +=1\n\nprint(result)'] | ['Runtime Error', 'Accepted'] | ['s144085238', 's478825411'] | [3064.0, 3064.0] | [18.0, 60.0] | [353, 517] |
p03805 | u203377003 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = list(map(int, input().split()))\n\nG = {}\nfor m in range(M):\n k, v = list(map(int, input().split()))\n G.setdefault(k, []).append(v)\n G.setdefault(v, []).append(k)\n # G[k] = list(set(G[k]))\n # G[v] = list(set(G[v]))\n\ncount = 0\nvisited = []\nvisited.append(1)\nhistory = []\n\n\ndef dfs(graph, start, visited=[]):\n global count\n if len(visited) == M:\n print(visited)\n if visited not in history:\n count += 1\n history.append(visited)\n # visited.append(start)\n for label in graph.get(start, []):\n if label not in visited:\n visited.append(label)\n dfs(graph, label, visited)\n visited = visited[0:-2]\n\n\ndfs(G, 1, visited)\nprint(count)', 'N, M = list(map(int, input().split()))\n\nG = {}\nfor m in range(M):\n k, v = list(map(int, input().split()))\n G.setdefault(k, []).append(v)\n G.setdefault(v, []).append(k)\n\ncount = 0\nvisited = []\nvisited.append(1)\n\n\ndef dfs(graph, start, visited=[]):\n global count\n if len(visited) == M:\n count += 1\n # visited.append(start)\n for label in graph.get(start, []):\n if label not in visited:\n visited.append(label)\n print(visited)\n visited = dfs(graph, label, visited)\n visited.pop(-1)\n return visited\n\n\ndfs(G, 1, visited)\nprint(count)\n', 'N, M = map(int, input().split())\nr = [[] * N for i in range(N)]\nreached = [0] * N\nreached[0] = 1\ncount = 0\n \ndef dfs(now):\n global count\n if all(reached):\n count += 1\n for next in r[now]:\n if reached[next] == 0:\n reached[next] = 1\n dfs(next)\n reached[next] = 0\n \nfor i in range(M):\n a, b = map(lambda x: int(x) - 1, input().split())\n r[a].append(b)\n r[b].append(a)\n \ndfs(0)\n \nprint(count)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s330587927', 's767991566', 's785311688'] | [3064.0, 3316.0, 3064.0] | [19.0, 52.0, 28.0] | [729, 609, 453] |
p03805 | u210827208 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\n\nX=[[] for _ in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n X[a-1].append(b-1)\n X[b-1].append(a-1)\n\nprint(X)\n\npath=[i for i in range(2,n+1)]\n\nvisited=[1]+[0]*(n-1)\n\ndef dfs(v):\n if visited==[1]*n:\n return 1\n res=0\n for x in X[v]:\n if visited[x]==0:\n visited[x]=1\n print(visited)\n res+=dfs(x)\n visited[x]=0\n return res\n\nprint(dfs(0))', 'n,m=map(int,input().split())\n\nX=[[] for _ in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n X[a-1].append(b-1)\n X[b-1].append(a-1)\n\nprint(X)\n\npath=[i for i in range(2,n+1)]\n\nvisited=[1]+[0]*(n-1)\n\ndef dfs(v):\n if visited==[1]*n:\n return 1\n res=0\n for x in X[v]:\n if visited[x]==0:\n visited[x]=1\n res+=dfs(x)\n visited[x]=0\n return res\n\nprint(dfs(0))', 'n,m=map(int,input().split())\n\nX=[[] for _ in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n X[a-1].append(b-1)\n X[b-1].append(a-1)\n\n\npath=[i for i in range(2,n+1)]\n\nvisited=[1]+[0]*(n-1)\n\ndef dfs(v):\n if visited==[1]*n:\n return 1\n res=0\n for x in X[v]:\n if visited[x]==0:\n visited[x]=1\n res+=dfs(x)\n visited[x]=0\n return res\n\nprint(dfs(0))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s333908316', 's721240601', 's642530267'] | [3444.0, 3064.0, 3064.0] | [51.0, 27.0, 27.0] | [457, 430, 421] |
p03805 | u214434454 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int,input().split())\nlis = [0 for i in range(m)]\nfor i in range(m):\n lis[i] = list(map(int,input().split()))\n \nseen = []\ncount = 0\nvisited = [0 for i in range(m)]\nr = 0\ndef route(x=1):\n for i in range(m):\n if lis[i][0] == x and visited[i] == 0:\n visited[i] = 1\n r += 1\n route(lis[i][1])\n visited[i] = 0\n r -= 1\n elif lis[i][1] == x and visited[i] == 0:\n visited[i] = 1\n r += 1\n route(lis[i][0])\n visited[i] = 0\n r -= 1\n if r == n-1:\n global count\n count += 1\n return\n \n \n \nroute(1)\nprint(count)', 'n, m = map(int,input().split())\nlis = [0 for i in range(m)]\nfor i in range(m):\n lis[i] = list(map(int,input().split()))\n \nseen = []\ncount = 0\ndef route(x=1):\n for i in range(m):\n if lis[i][0] == x and visited[i] == 0:\n visited[i] = 1\n route(lis[i][1])\n visited[i] = 0\n elif lis[i][1] == x and visited[i] == 0:\n visited[i] = 1\n route(lis[i][0])\n visited[i] = 0\n r = 0\n for j in visited:\n r += j\n if r == n-1:\n global count\n count += 1\n return\n \n \n \nroute(1)\nprint(count)', 'n, m = map(int,input().split())\nlis = [0 for i in range(m)]\nfor i in range(m):\n lis[i] = list(map(int,input().split()))\n \nseen = []\ncount = 0\nvisited = [0 for i in range(n)]\ndef route(x=1):\n visited[x-1] = 1\n if [1]*n == visited:\n global count\n count +=1\n return\n for i in range(m):\n if lis[i][0] == x and visited[lis[i][1]-1] == 0:\n route(lis[i][1])\n visited[lis[i][1]-1] = 0\n elif lis[i][1] == x and visited[lis[i][0]-1] == 0:\n route(lis[i][0])\n visited[lis[i][0]-1] = 0\n return\n \n \nroute(1)\nprint(count)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s577735839', 's938787218', 's123387330'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 67.0] | [703, 648, 621] |
p03805 | u217627525 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\npaths=[]\nfor i in range(n):\n paths.append([0]*n)\nfor i in range(m):\n a,b=map(int,input().split())\n paths[a-1][b-1]=1\n paths[b-1][a-1]=1\nvisited=[0]*n\n\ndef dfs(now,depth):\n if visited[now]==1:\n return 0\n elif depth==n-1:\n return 1\n else:\n visited[now]=1\n total=0\n for i in range(n):\n if paths[now][i]==1:\n total+=dfs(i,depth+1)\n print(total)\n visited[now]=0\n return total\n\nprint(dfs(0,0))', 'n,m=map(int,input().split())\npaths=[]\n\nfor i in range(n):\n paths.append([0]*n)\n\nfor i in range(m):\n a,b=map(int,input().split())\n paths[a-1][b-1]=1\n paths[b-1][a-1]=1\nvisited=[0]*n\n\ndef dfs(now,depth):\n if visited[now]==1:\n return 0\n elif depth==n-1:\n return 1\n else:\n visited[now]=1\n total=0\n for i in range(n):\n if paths[now][i]==1:\n total+=dfs(i,depth+1)\n visited[now]=0\n return total\nprint(dfs(0,0))'] | ['Wrong Answer', 'Accepted'] | ['s359628227', 's862312380'] | [3832.0, 3064.0] | [74.0, 40.0] | [527, 499] |
p03805 | u218843509 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = list(map(int, input().split()))\npaths = [list(map(int, input().split())) for _ in range(m)]\n\nvisited = [1]\nrest = [i for i in range(2, n + 1)]\nans = 0\n\ndef dfs(num):\n if rest == []:\n print(visited)\n global ans\n ans += 1\n for i in range(m):\n if num in paths[i]:\n other = paths[i][1 - paths[i].index(num)]\n if other in rest:\n # print(other)\n visited.append(other)\n rest.remove(other)\n # print(visited, rest)\n dfs(other)\n visited.remove(other)\n rest.append(other)\n\ndfs(1)\nprint(ans)', 'n, m = list(map(int, input().split()))\npaths = [list(map(int, input().split())) for _ in range(m)]\n\nvisited = [1]\nrest = [i for i in range(2, n + 1)]\nans = 0\n\ndef dfs(num):\n if rest == []:\n # print(visited)\n global ans\n ans += 1\n for i in range(m):\n if num in paths[i]:\n other = paths[i][1 - paths[i].index(num)]\n if other in rest:\n # print(other)\n visited.append(other)\n rest.remove(other)\n # print(visited, rest)\n dfs(other)\n visited.remove(other)\n rest.append(other)\n\ndfs(1)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s415022711', 's901302914'] | [3188.0, 3064.0] | [92.0, 82.0] | [647, 649] |
p03805 | u221061152 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nab = []\nfor _ in range(n):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n ab.append({a,b})\nimport itertools\n\ncnt = 0\nfor v in itertools.permutations(range(1,n)):\n l = 0\n ok = True\n for v2 in v:\n if {l,v2} not in ab:\n ok = False\n break\n l = v2\n if ok:\n print(v)\n cnt += 1\n \nprint(cnt)', 'n,m=map(int,input().split())\nab = []\nfor _ in range(m):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n ab.append({a,b})\nimport itertools\n\ncnt = 0\nfor v in itertools.permutations(range(1,n)):\n l = 0\n ok = True\n for v2 in v:\n if {l,v2} not in ab:\n ok = False\n break\n l = v2\n if ok:\n #print(v)\n cnt += 1\n \nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s341710144', 's279351646'] | [9196.0, 9212.0] | [32.0, 39.0] | [339, 340] |
p03805 | u223646582 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nN, M = map(int, input().split())\n\nG = {k: set() for k in range(N+1)}\nfor _ in range(M):\n a, b = map(int, input().split())\n \n G[a].add(b)\n G[b].add(a)\nprint(G)\n\nans = 0\nfor p in itertools.permutations(range(2, N+1)):\n print(p)\n c = 1\n for n in p:\n if n not in G[c]:\n break\n c = n\n else:\n ans += 1\n\nprint(ans)\n', 'N, M = map(int, input().split())\nG = {k: [] for k in range(N+1)}\nfor _ in range(N):\n a, b = map(int, input().split())\n \n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nvisited = [False]*N\nvisited[0] = True\n\n\ndef dfs(v):\n if all(visited):\n ans += 1\n return\n for nv in G[i]:\n if visited[nv] is False:\n visited[nv] = True\n dfs(nv)\n visited[nv] = False\n return\n\n\nans = 0\ndfs(0)\nprint(ans)\n', 'N, M = map(int, input().split())\n\nG = {k: [] for k in range(N)} # 0-indexed\nfor _ in range(M):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\n\ndef dfs(p, arrived):\n if arrived == 2**N-1:\n return 1\n\n ret = 0\n for n in G[p]:\n if (arrived >> n) & 1 == 0:\n ret += dfs(n, arrived+2**n)\n return ret\n\n\narrived = 1\nprint(dfs(0, arrived))\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s071962596', 's084050858', 's810578308'] | [3188.0, 3064.0, 3064.0] | [31.0, 17.0, 33.0] | [398, 470, 405] |
p03805 | u227082700 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nedge=[n*[0]for _ in range(n)]\nfor i in range(m):\n\ta,b=map(int,input().split())\n\ta-=1\n\tb-=1\n\tedge[a][b]=edge[b][a]=1\nfrom itertools import permutations\nans=0\nfor i in permutations([j for j in range(1,n)],n-1):\n\tf=True\n\tt=[0]+i\n\tfor j in range(1,n):\n\t\tif edge[t[j-1]][t[j]]==0:f=False\n\tif f:ans+=1\nprint(ans)', 'n,m=map(int,input().split());a=[[],[]];ans=0\nfor i in range(m):aa,bb=map(int,input().split());a[0].append(aa);a[1].append(bb)\ndef d(n,nl,ml):\n if sorted(nl+[n])==[i+1for i in range(n)]:return 1\n if n in nl:return 0\n l=len(ml[0]);ans=0\n for i in range(l):\n c=[ml[0][:i]+ml[0][i+1:],ml[1][:i]+ml[1][i+1:]]\n if ml[0][i]==n:ans+=d(ml[1][i],nl+[n],c)\n if ml[1][i]==n:ans+=d(ml[0][i],nl+[n],c)\n return ans\nfor i in range(m):\n if a[0][i]==1:\n c=[a[0][:i]+a[0][i+1:],a[1][:i]+a[1][i+1:]]\n ans+=d(a[1][i],[1],c)\nprint(ans)', 'n,m=map(int,input().split())\nedge=[n*[0]for _ in range(n)]\nfor i in range(m):\n\ta,b=map(int,input().split())\n\ta-=1\n\tb-=1\n\tedge[a][b]=edge[b][a]=1\nfrom itertools import permutations\nans=0\nfor i in permutations([j for j in range(1,n)],n-1):\n\tf=True\n\tt=[0]+list(i)\n\tfor j in range(1,n):\n\t\tif edge[t[j-1]][t[j]]==0:f=False\n\tif f:ans+=1\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s684873941', 's689873186', 's303957688'] | [3064.0, 3064.0, 3064.0] | [17.0, 486.0, 31.0] | [335, 534, 341] |
p03805 | u228223940 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import bisect\nn,m = map(int,input().split())\n\ng = [[ ] for i in range(n+1)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n g[a].append(b)\n g[b].append(a)\n\n \n #g[a][] = b\n #g[a].append(b)\n #g[b].append(a)\n\n#g[4].sort()\n \nans = 0\n\ndef dfs(x,check):\n #print(check,x)\n ans = 0\n if not False in check:\n print(ans)\n return 1\n #check[x] = 0\n #print(x)\n #print(check)\n for i in g[x]:\n if check[i] == True:\n continue\n #print(i,check)\n check[i] = True\n ans += dfs(i,check)\n check[i] = False\n \n return ans\n \ncheck = [False] * (n+1)\ncheck[0] = True\ncheck[1] = True\n\nprint(dfs(1,check))\n\n', 'import bisect\nn,m = map(int,input().split())\n\ng = [[ ] for i in range(n+1)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n g[a].append(b)\n g[b].append(a)\n\n \n #g[a][] = b\n #g[a].append(b)\n #g[b].append(a)\n\n#g[4].sort()\n \nans = 0\n\ndef dfs(x,check):\n #print(check,x)\n ans = 0\n if not False in check:\n #print(ans)\n return 1\n #check[x] = 0\n #print(x)\n #print(check)\n for i in g[x]:\n if check[i] == True:\n continue\n #print(i,check)\n check[i] = True\n ans += dfs(i,check)\n check[i] = False\n \n return ans\n \ncheck = [False] * (n+1)\ncheck[0] = True\ncheck[1] = True\n\nprint(dfs(1,check))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s143004704', 's438210799'] | [3700.0, 3064.0] | [28.0, 24.0] | [737, 738] |
p03805 | u247554097 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\n\nN, M = map(int, input().split())\nNeighbor_list = [[] for _ in range(N)]\nfor _ in range(M):\n s, t = map(int, input().split())\n Neighbor_list[s-1].append(t-1)\n Neighbor_list[t-1].append(s-1)\n\n\ndef dfs(cur, path):\n if len(path) == N:\n return 1\n else:\n ret = 0\n for neighbor in Neighbor_list[cur]:\n if neighbor not in path:\n next_list = path[:]\n next_list.append(neighbor)\n ret += dfs(neighbor, next_list)\n return ret\n\n\nprint(dfs(0, []))\n', '\n\nN, M = map(int, input().split())\nNeighbor_list = [[] for _ in range(N)]\nfor _ in range(M):\n s, t = map(int, input().split())\n Neighbor_list[s-1].append(t-1)\n Neighbor_list[t-1].append(s-1)\n\n\ndef dfs(cur, path):\n if len(path) == N:\n return 1\n else:\n ret = 0\n for neighbor in Neighbor_list[cur]:\n if neighbor not in path:\n next_list = path[:]\n next_list.append(neighbor)\n ret += dfs(neighbor, next_list)\n return ret\n\n\nprint(dfs(0, [0]))\n'] | ['Wrong Answer', 'Accepted'] | ['s055024297', 's651500148'] | [3064.0, 3064.0] | [89.0, 27.0] | [662, 663] |
p03805 | u248967559 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import copy\n\nN, M = [ int(x) for x in input().split()]\n\nclass Node:\n def __init__(self, id):\n self.id = id\n self.path = []\n self.passed = False\n def __str__(self):\n return "id: " + str(self.id) + " path: " + str(self.path) + " passed: " + str(self.passed)\n\nnodes = []\nfor i in range(N):\n nodes.append(Node(i))\n\nfor i in range(M):\n from_id, to_id = [ int(x) - 1 for x in input().split()]\n nodes[from_id].path.append(to_id)\n nodes[to_id].path.append(from_id)\n\ndef if_all_passed(nodes_current):\n for node in nodes_current:\n if not node.passed:\n return False\n return True\n\ndef go_child(id_new, nodes_current):\n print(id_new, nodes_current[0])\n nodes_current[id_new].passed = True\n if if_all_passed(nodes_current):\n return 1\n\n count = 0\n for i in nodes[id_new].path:\n if not nodes_current[i].passed:\n count += go_child(i, copy.deepcopy(nodes_current))\n return count\n\ncount = go_child(0, nodes)\nprint(count)\n', 'import copy\n\nN, M = [ int(x) for x in input().split() ]\n\nclass Node:\n def __init__(self, id):\n self.id = id\n self.path = []\n def __str__(self):\n return "id: " + str(self.id) + " path: " + str(self.path)\n\nnodes = []\nfor i in range(N):\n nodes.append(Node(i))\n\nfor i in range(M):\n from_id, to_id = [ int(x) - 1 for x in input().split() ]\n nodes[from_id].path.append(to_id)\n nodes[to_id].path.append(from_id)\n\ndef if_all_passed(passed_nodes):\n if len(passed_nodes) == N:\n return True\n else:\n return False\n\ndef go_child(id_new, passed_nodes):\n passed_nodes.append(id_new)\n if if_all_passed(passed_nodes):\n return 1\n\n count = 0\n for i in nodes[id_new].path:\n if not i in passed_nodes:\n count += go_child(i, copy.deepcopy(passed_nodes))\n return count\n\ncount = go_child(0, [])\nprint(count)\n'] | ['Wrong Answer', 'Accepted'] | ['s072190468', 's271978044'] | [4052.0, 3572.0] | [2104.0, 120.0] | [1015, 881] |
p03805 | u252405453 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def abc054c_one_stroke_path():\n import itertools\n n, m = map(int, input().split())\n e = [set() for _ in range(n + 1)]\n for _ in range(m):\n a, b = map(int, input().split())\n e[a].add(b)\n e[b].add(a)\n pattern = itertools.permutations(range(2, n + 1))\n cnt = 0\n for p in pattern:\n p_m = [1] + list(p)\n for i in range(n - 1):\n if p_m[i+1] not in e[p_m[i]]:\n break\n else:\n cnt += 1\n print(cnt)', 'def abc054c_one_stroke_path():\n import itertools\n n, m = map(int, input().split())\n e = [set() for _ in range(n + 1)]\n for _ in range(m):\n a, b = map(int, input().split())\n e[a].add(b)\n e[b].add(a)\n pattern = itertools.permutations(range(2, n + 1))\n cnt = 0\n for p in pattern:\n p_m = [1] + list(p)\n for i in range(n - 1):\n if p_m[i+1] not in e[p_m[i]]:\n break\n else:\n cnt += 1\n print(cnt)\n\n\nabc054c_one_stroke_path()'] | ['Wrong Answer', 'Accepted'] | ['s677139927', 's378656986'] | [9068.0, 9212.0] | [23.0, 31.0] | [491, 519] |
p03805 | u255280439 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in input().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\nans = 0\nN, M = 0, 0\nA = None\n\ndef dfs(current_node, past_nodes, depth):\n global ans\n\n if depth == N:\n ans += 1\n return\n \n for next_node_i in range(1, N+1):\n if A[current_node][next_node_i] and next_node_i not in past_nodes:\n past_nodes.append(next_node_i)\n dfs(next_node_i, past_nodes, depth+1)\n past_nodes.remove(next_node_i)\n \n\ndef main():\n global N\n global M\n global A\n\n N, M = li_input()\n A = [[0] * (N+1) for _ in range(N+1)]\n\n for i in range(M):\n a, b = li_input()\n A[a][b] = 1\n A[b][a] = 1\n\n dfs(1, [], 1)\n print(ans)\n\n\nmain()\n", "import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in input().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\nans = 0\nN, M = 0, 0\nA = None\n\ndef dfs(current_node, past_nodes, depth):\n global ans\n\n if depth == N:\n ans += 1\n return\n \n for next_node_i in range(1, N+1):\n if A[current_node][next_node_i] and next_node_i not in past_nodes:\n past_nodes_ = past_nodes[:]\n past_nodes_.append(next_node_i)\n dfs(next_node_i, past_nodes_, depth+1)\n \n\ndef main():\n global N\n global M\n global A\n\n N, M = li_input()\n A = [[0] * (N+1) for _ in range(N+1)]\n\n for i in range(M):\n a, b = li_input()\n A[a][b] = 1\n A[b][a] = 1\n\n dfs(1, [], 1)\n print(ans)\n\n\nmain()\n", "import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in input().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\nans = 0\nN, M = 0, 0\nA = None\n\ndef dfs(current_node, past_nodes, depth):\n global ans\n\n if depth == N:\n ans += 1\n return\n \n for next_node_i in range(1, N+1):\n if A[current_node][next_node_i] and next_node_i not in past_nodes:\n past_nodes.append(next_node_i)\n dfs(next_node_i, past_nodes, depth+1)\n past_nodes.remove(next_node_i)\n \n\ndef main():\n global N\n global M\n global A\n\n N, M = li_input()\n A = [[0] * (N+1) for _ in range(N+1)]\n\n for i in range(M):\n a, b = li_input()\n A[a][b] = 1\n A[b][a] = 1\n\n dfs(1, [1], 1)\n print(ans)\n\n\nmain()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s521022554', 's822906979', 's319759653'] | [4872.0, 5140.0, 4872.0] | [92.0, 95.0, 54.0] | [3613, 3612, 3614] |
p03805 | u282228874 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn,m = map(int,input().split())\nD = [[0]*n for i in range(n)]\nfor i in range(m):\n\ta,b = map(int,input().split())\n\tD[a-1][b-1] = 1\n\tD[b-1][a-1] = 1\nprint(D)\n\ncnt = 0\nfor a in permutations(range(n)):\n\tprint(a)\n\tif a[0] != 0:\n\t\tbreak\n\ttmp = 1\n\tfor i in range(n-1):\n\t\ttmp = tmp * D[a[i]][a[i+1]]\n\tcnt += tmp\nprint(cnt)', 'n,m = map(int, input().split())\nD = [list() for i in range(n)]\nfor i in range(m):\n a,b = map(int,input().split())\n D[a-1].append(b-1)\n D[b-1].append(a-1)\n\nd = [0]*n\nd[0] = 1\ncnt = 0\n\ndef dfs(x):\n global cnt\n if all(d):\n cnt += 1\n return\n for i in D[x]:\n if d[i] == 0:\n d[i] = 1\n dfs(i)\n d[i] = 0\n\ndfs(0)\nprint(cnt)'] | ['Wrong Answer', 'Accepted'] | ['s294297356', 's228624862'] | [3188.0, 3064.0] | [39.0, 25.0] | [349, 344] |
p03805 | u304058693 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools as it\n\nn, m = map(int, input().split())\na = list(list(map(int, input().split())) for _ in range(m))\n\nprint(a)\n\n\nfor i in range(len(a)):\n a.append([a[i][1],a[i][0]])\nprint(a)\n\n\n\nlis = list(it.permutations(range(2, n + 1)))\n#print(lis)\nfor i in range(len(lis)):\n lis[i] = (1,) + lis[i]\n#print(lis)\n\n\nlis2 = []\nfor i in range(len(lis)):\n lis[i] = list(lis[i])\n lis2.append(lis[i])\nprint(lis2)\n\n\nfor i in range(len(lis2)):\n flag = 0\n for j in range(len(lis2[i]) - 1):\n for k in range(len(a)):\n if lis2[i][j : j + 2] == a[k]:\n flag += 1\n #print(lis[i][j : j + 2], a[k])\n #print(lis[i][j : j + 2])\nprint(flag)\n', 'import itertools as it\n\nn, m = map(int, input().split())\na = list(list(map(int, input().split())) for _ in range(m))\n\n#print(a)\n\n\nfor i in range(len(a)):\n a.append([a[i][1],a[i][0]])\n#print(a)\n\n\n\nlis = list(it.permutations(range(2, n + 1)))\n#print(lis)\nfor i in range(len(lis)):\n lis[i] = (1,) + lis[i]\n#print(lis)\n\n\nlis2 = []\nfor i in range(len(lis)):\n lis[i] = list(lis[i])\n lis2.append(lis[i])\n#print(lis2)\n\n\n#lis3 = []\nans = 0\nfor i in range(len(lis2)):\n check = True\n for j in range(len(lis2[i]) - 1):\n if lis2[i][j : j + 2] not in a:\n check = False\n if check:\n ans += 1\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s976182140', 's317036395'] | [10280.0, 10172.0] | [464.0, 65.0] | [831, 770] |
p03805 | u314057689 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from copy import deepcopy as dcopy\ndef main():\n global count,N,M,edges,stack\n N, M = map(int, input().split())\n edges = [[0]*N for n in range(N)]\n for m in range(M):\n a,b = map(lambda x:int(x)-1,input().split())\n edges[a][b] = 1\n edges[b][a] = 1\n\n count = 0\n stack = [[[0], [0]]]\n while len(stack) != 0:\n tansaku = stack.pop()\n next_list = [n for n,v in enumerate(edges[tansaku[0][-1]]) if v == 1]\n search(tansaku, next_list)\n print(count)\n\ndef search(tansaku, next_list):\n global count, stack\n for node in next_list:\n tmp_tansaku = dcopy(tansaku)\n tmp_node = tmp_tansaku[0]\n houmonzumi = tmp_tansaku[1]\n if node in houmonzumi:\n pass\n else:\n houmonzumi.append(node)\n if len(houmonzumi) == N:\n count += 1\n else:\n tmp_node.append(node)\n stack.append([tmp_node, houmonzumi])\n', 'from copy import deepcopy as dcopy\ndef main():\n global count,N,M,edges,stack\n N, M = map(int, input().split())\n edges = [[0]*N for n in range(N)]\n for m in range(M):\n a,b = map(lambda x:int(x)-1,input().split())\n edges[a][b] = 1\n edges[b][a] = 1\n\n count = 0\n stack = [[[0], [0]]]\n while len(stack) != 0:\n tansaku = stack.pop()\n next_list = [n for n,v in enumerate(edges[tansaku[0][-1]]) if v == 1]\n search(tansaku, next_list)\n print(count)\n\ndef search(tansaku, next_list):\n global count, stack\n for node in next_list:\n tmp_tansaku = dcopy(tansaku)\n tmp_node = tmp_tansaku[0]\n houmonzumi = tmp_tansaku[1]\n if node in houmonzumi:\n pass\n else:\n houmonzumi.append(node)\n if len(houmonzumi) == N:\n count += 1\n else:\n tmp_node.append(node)\n stack.append([tmp_node, houmonzumi])\n\nif __name__ == "__main__":# {{{\n try:\n import test\n test.test()\n except:\n main()# }}}\n'] | ['Wrong Answer', 'Accepted'] | ['s290953265', 's269246091'] | [3544.0, 3544.0] | [24.0, 923.0] | [968, 1082] |
p03805 | u318233626 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["from sys import setrecursionlimit\nsetrecursionlimit(10 ** 10)\nn, m = map(int, input().split())\nP = [[] for i in range(m)] #Pass\nfor i in range(m):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1 \n P[a].append(b)\n P[b].append(a)\n#print(P)\n\nc = 0 #cursol\nR = [0 for i in range(m)] #Record\ntm = 1 #time\n\ndef all_search_dfs(c:int, tm:int, R:list):\n if R[c] == 0:\n R[c] = 1\n if tm < n:\n return point_calculate(c, tm, R)\n elif tm == n:\n return 1\n else:\n return 0\n else:\n return 0\n\ndef point_calculate(c:int, tm:int, R:list):\n #print('c = ', c)\n p = 0\n #print('check = ', P[c])\n for i in range(len(P[c])):\n R2 = R[:]\n #print('before = ', R2)\n tmp = all_search_dfs(P[c][i], tm + 1, R2)\n #print('after = ', R2)\n #print('tmp = ', tmp)\n p += tmp\n #print('p = ', p)\n return p\n\nprint(all_search_dfs(c, tm, R))", "from sys import setrecursionlimit\nsetrecursionlimit(4100000)\nn, m = map(int, input().split())\nP = [[] for i in range(n)] #Pass\nfor i in range(m):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1 \n P[a].append(b)\n P[b].append(a)\n#print(P)\n\nc = 0 #cursol\nR = [0 for i in range(n)] #Record\ntm = 1 #time\n\ndef all_search_dfs(c:int, tm:int, R:list):\n if R[c] == 0:\n R[c] = 1\n if tm < n:\n return point_calculate(c, tm, R)\n elif tm == n:\n return 1\n else:\n return 0\n else:\n return 0\n\ndef point_calculate(c:int, tm:int, R:list):\n #print('c = ', c)\n p = 0\n #print('check = ', P[c])\n for i in range(len(P[c])):\n R2 = R[:]\n #print('before = ', R2)\n tmp = all_search_dfs(P[c][i], tm + 1, R2)\n #print('after = ', R2)\n #print('tmp = ', tmp)\n p += tmp\n #print('p = ', p)\n return p\n\nprint(all_search_dfs(c, tm, R))"] | ['Runtime Error', 'Accepted'] | ['s434121574', 's017865124'] | [8988.0, 9192.0] | [21.0, 36.0] | [961, 960] |
p03805 | u322229918 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nimport numpy as np\nN, M = map(int, input().split(" "))\nmat = [[0] * n for _ in range(n)]\nfor _ in range(M):\n v1, v2 = map(int, input().split(" "))\n mat[v1 - 1][v2 - 1] = mat[v2 - 1][v1 - 1] = 1\n\ncount = 0\nfor line in permutations(np.arange(N - 1) + 2):\n vtxs = [1] + list(line)\n for i in range(N - 1):\n v1, v2 = vtxs[i], vtxs[i + 1]\n if mat[v1 - 1][v2 - 1] == 0:\n break\n else:\n count += 1\nprint(count)', 'from itertools import permutations\nimport numpy as np\nN, M = map(int, input().split(" "))\nedges = []\nfor _ in range(M):\n edges += [list(map(int, input().split(" ")))]\n\ncount = 0\nfor line in permutations(np.arange(N - 1) + 2):\n vtxs = [1] + list(line)\n for i in range(N - 1):\n edge = sorted([vtxs[i], vtxs[i + 1]])\n if edge not in edges:\n break\n else:\n count += 1\nprint(count)'] | ['Runtime Error', 'Accepted'] | ['s610820984', 's954689092'] | [21800.0, 12428.0] | [312.0, 518.0] | [495, 431] |
p03805 | u338597441 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools as it\n\nn,m=map(int,input().split())\nans=[]\nfor i in range(n):\n a,b=map(int,input().split())\n ans.append([a,b])\n ans.append([b,a])\n \n\nfor e in it.permutations(range(n)):\n count,a=0,0\n if e[0]!=0:\n break\n \n for i in range(len(e)-1):\n if [e[i]+1,e[i+1]+1] in ans:\n count=1\n else:\n count=0\n \n a+=count\n \nprint(a)', 'import itertools as it\n\nn,m=map(int,input().split())\nans=[]\nfor i in range(n):\n a,b=map(int,input().split())\n ans.append([a,b])\n ans.append([b,a])\n \na=0\nfor e in it.permutations(range(n)):\n count=0\n if e[0]!=0:\n break\n \n for i in range(len(e)-1):\n if [e[i]+1,e[i+1]+1] in ans:\n count*=1\n else:\n count*=0\n break\n \n a+=count\n \nprint(a)', 'import itertools as it\n\nn,m=map(int,input().split())\nans=[]\nfor i in range(m):\n a,b=map(int,input().split())\n ans.append([a,b])\n ans.append([b,a])\n \na=0\nfor e in it.permutations(range(n)):\n #print(e)\n count=1\n if e[0]!=0:\n break\n \n for i in range(n-1):\n if [e[i]+1,e[i+1]+1] in ans:\n count*=1\n else:\n count*=0\n break\n \n a+=count\n \nprint(a)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s038260829', 's305547396', 's497799678'] | [9068.0, 9152.0, 9128.0] | [51.0, 35.0, 69.0] | [407, 426, 435] |
p03805 | u359358631 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\n\ndef main():\n N, M = map(int, input().split())\n node_lst = [x for x in range(N)]\n edge_lst = [list(map(int, input().split())) for _ in range(M)]\n ans = 0\n print(edge_lst)\n\n for route in itertools.permutations(node_lst):\n is_visited = [False] * N\n is_visited[0] = True\n if route[0] != 0:\n continue\n\n for i in range(N - 1):\n if [route[i] + 1, route[i + 1] + 1] in edge_lst and is_visited[route[i + 1]] == False:\n is_visited[route[i + 1]] = True\n if [route[i + 1] + 1, route[i] + 1] in edge_lst and is_visited[route[i + 1]] == False:\n is_visited[route[i + 1]] = True\n\n if is_visited == [True] * N:\n ans += 1\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'import itertools\n\n\ndef main():\n N, M = map(int, input().split())\n node_lst = [x for x in range(N)]\n edge_lst = [list(map(int, input().split())) for _ in range(M)]\n ans = 0\n\n for route in itertools.permutations(node_lst):\n is_visited = [False] * N\n is_visited[0] = True\n if route[0] != 0:\n continue\n\n for i in range(N - 1):\n if [route[i] + 1, route[i + 1] + 1] in edge_lst and is_visited[route[i + 1]] == False:\n is_visited[route[i + 1]] = True\n if [route[i + 1] + 1, route[i] + 1] in edge_lst and is_visited[route[i + 1]] == False:\n is_visited[route[i + 1]] = True\n\n if is_visited == [True] * N:\n ans += 1\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s198683084', 's608711699'] | [9100.0, 9204.0] | [82.0, 84.0] | [806, 786] |
p03805 | u360515075 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['input()', 'from collections import defaultdict\nfrom collections import deque\n\nN, M = map(int, input().split())\n\nD = defaultdict(list)\nfor i in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n D[a].append(b)\n D[b].append(a)\n\nq = deque([])\nq.append(0)\n\nans = 0\ndef dfs(n, q):\n print (n, D[n], q)\n global ans\n q.append(n)\n if len(q) == N:\n ans += 1\n else:\n for b in D[n]:\n if b not in q:\n dfs(b, q)\n q.pop()\n\ndfs(0, [])\nprint (ans)', 'from collections import defaultdict\nfrom collections import deque\n\nN, M = map(int, input().split())\n\nD = defaultdict(list)\nfor i in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n D[a].append(b)\n D[b].append(a)\n\nq = deque([])\nq.append(0)\n\nans = 0\ndef dfs(n, q):\n global ans\n q.append(n)\n if len(q) == N:\n ans += 1\n else:\n for b in D[n]:\n if b not in q:\n dfs(b, q)\n q.pop()\n\ndfs(0, [])\nprint (ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s527632156', 's948644803', 's135563824'] | [2940.0, 3956.0, 3316.0] | [17.0, 69.0, 30.0] | [7, 464, 443] |
p03805 | u367130284 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import collections as c\nn,m=map(int,input().split())\nd=c.defaultdict(list)\nfor s in range(m):\n a,b=map(int,input().split())\n d[a].append(b)\nprint(d)\nans=0\nmovecount=0\ndef search(defaultdict,list):\n global movecount\n global ans\n movecount+=1\n if list==[]:\n if movecount==m:\n ans+=1\n movecount-=1\n else:\n movecount-=1\n for item in list:\n # print(item,"i")\n \n search(defaultdict,defaultdict[item])\n return ans\nprint(search(d,d[1]))', 'from collections import *\nn,m=map(int,input().split())\n\nd=defaultdict(list)\n\nfor s in m*[0]:\n a,b=map(int,input().split())\n d[a].append(b)\n d[b].append(a)\n\nprint(d)\n\n\n\ndef DFS_dict(point,TFlist):\n# print(TFlist)\n# print(d[point])\n if not False in TFlist:\n return 1\n ans=0\n for i in d[point]:\n if TFlist[i-1]:\n continue \n TFlist[i-1]=True \n ans+=DFS_dict(i,TFlist)\n TFlist[i-1]=False\n return ans\n\nTFlist=[True]+[False]*(n-1)\nprint(DFS_dict(1,TFlist))', 'from collections import *\nn,m=map(int,input().split())\nd=defaultdict(list)\nfor s in m*[0]:\n a,b=map(int,input().split())\n d[a].append(b)\n d[b].append(a)\ndef DFS_dict(point,TFlist):\n if all(TFlist):\n return 1\n ans=0\n for i in d[point]:\n if TFlist[i-1]:\n continue\n TFlist[i-1]=True\n ans+=DFS_dict(i,TFlist)\n TFlist[i-1]=False\n return ans\nTFlist=[True]+[False]*(n-1)\nprint(DFS_dict(1,TFlist))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s767920648', 's960441999', 's233817741'] | [3316.0, 3316.0, 3316.0] | [21.0, 28.0, 28.0] | [482, 635, 456] |
p03805 | u370852395 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["# -*- coding: utf-8 -*-\nN,M = map(int, input().split())\nG = [[] for j in range(N)]\n\nfor i in range(M):\n a,b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\nprint(G)\nvisited = [False]*N\nvisited[0] = True\n\ndef DFS(v,visited):\n \n if all(visited):\n return 1\n ans = 0\n for i in G[v]:\n print('i',i)\n if visited[i]:\n continue\n visited[i] = True\n ans += DFS(i,visited)\n visited[i] = False\n return ans\n\nprint(DFS(0,visited))\n", '# -*- coding: utf-8 -*-\nN,M = map(int, input().split())\nG = [[] for j in range(N)]\n\nfor i in range(M):\n a,b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\nvisited = [False]*N\nvisited[0] = True\n\ndef DFS(v,visited):\n \n if all(visited):\n return 1\n ans = 0\n for i in G[v]:\n if visited[i]:\n continue\n visited[i] = True\n ans += DFS(i,visited)\n visited[i] = False\n return ans\n\nprint(DFS(0,visited))\n'] | ['Wrong Answer', 'Accepted'] | ['s087947525', 's682167924'] | [9236.0, 9120.0] | [58.0, 28.0] | [578, 548] |
p03805 | u373958718 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import sys\nsys.setrecursionlimit(10 ** 6)\nn,m=map(int,input().split())\ng=[[]for i in range(n)]; ans=0\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1; b-=1\n g[a].append(b)\n g[b].append(a)\n# print(g)\ndef dfs(x,visited):\n global ans\n # print(x,visited)\n for p in g[x]:\n if visited[p]==0:\n visited[p]=1\n if visited.count(1)==n:\n ans+=1\n # print(ans)\n return\n dfs(p,visited)\n visited[p]=0\nv=[0]*n\nv[0]=1\ndfs(0,v)\nprint(ans)', 'import sys\nsys.setrecursionlimit(10 ** 6)\nn,m=map(int,input().split())\ng=[[]for i in range(n)]; ans=0\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1; b-=1\n g[a].append(b)\n g[b].append(a)\n# print(g)\ndef dfs(x,visited):\n global ans\n # print(x,visited)\n for p in g[x]:\n if visited[p]==0:\n visited[p]=1\n if visited.count(1)==n:\n ans+=1\n # print(ans)\n else: \n dfs(p,visited)\n visited[p]=0\nv=[0]*n\nv[0]=1\ndfs(0,v)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s457522554', 's166467833'] | [3064.0, 3064.0] | [17.0, 24.0] | [477, 477] |
p03805 | u375616706 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["def bit_dp(N, Adj):\n dp = [[0]*N for i in range(1 << N)]\n #dp[{0},0] = 1\n\n dp[1][0] = 1\n\n for S in range(1 << N):\n for v in range(N):\n \n if (S & (1 << v)) == 0:\n continue\n\n \n sub = S ^ (1 << v)\n\n for u in range(N):\n \n if (sub & (1 << u)) and (Adj[u][v]):\n dp[S][v] += dp[sub][u]\n ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))\n return ans\n\n\ndef main():\n N, M = map(int, input().split())\n Adj = [[False]*N for _ in range(N)]\n\n for _ in range(M):\n a, b = map(int, input().split())\n Adj[a-1][b-1] = 1\n Adj[b-1][a-1] = 1\n ans = bit_dp(N, Adj)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "def bit_dp(N, Adj):\n dp = [[0]*N for i in range(1 << N)]\n #dp[{0},0] = 1\n\n dp[1][0] = 1\n\n for S in range(1 << N):\n for v in range(N):\n \n if (S & (1 << v)) == 0:\n continue\n\n \n sub = S ^ (1 << v)\n\n for u in range(N):\n \n if (sub & (1 << u)) and Adj[u][v]:\n dp[S][v] += dp[sub][u]\n ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))\n return ans\n\n\ndef main():\n N, M = map(int, input().split())\n Adj = [[False]*N for _ in range(N)]\n\n for _ in range(M):\n a, b = map(int, input().split())\n Adj[a-1][b-1] = True\n Adj[b-1][a-1] = True\n ans = bit_dp(N, Adj)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "def bit_dp(N, Adj):\n dp = [[0]*N for i in range(1 << N)]\n #dp[{0},0] = 1\n\n dp[1][0] = 1\n\n for S in range(1 << N):\n for v in range(N):\n \n if (S & (1 << v)) == 0:\n continue\n\n \n sub = S ^ (1 << v)\n\n for u in range(N):\n \n if (sub & (1 << u)) and (Adj[u][v]):\n dp[S][v] += dp[sub][u]\n ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))\n return ans\n\n\ndef main():\n N, M = map(int, input().split())\n Adj = [[False]*N for _ in range(N)]\n\n for _ in range(M):\n a, b = map(int, input().split())\n Adj[a-1][b-1] = 1\n Adj[b-1][a-1] = 1\n ans = bit_dp(N, Adj)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s096847948', 's706311117', 's432482125'] | [3064.0, 3064.0, 3064.0] | [18.0, 19.0, 20.0] | [923, 927, 915] |
p03805 | u375695365 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nab=[]\nfor i in range(m):\n ab.append(list(map(int,input().split())))\n\nans=0\ndef dfs(start,finish):\n global ans\n finish.add(start)\n # print(finish)\n if len(finish)==n:\n ans+=1\n \n for i in adlist[start-1]:\n if i not in finish:\n # print(i)\n dfs(i,finish)\n\nadlist=[]\nfor h in range(n): \n adlist.append([])\nfor j in range(m):\n x=ab[j][0]\n y=ab[j][1]\n adlist[x-1].append(y)\n adlist[y-1].append(x)\nfinish=set()\n#print(adlist)\ndfs(1,finish)\nprint(ans)', 'import copy\nn,m=map(int,input().split())\nab=[]\nfor i in range(m):\n ab.append(list(map(int,input().split())))\n\nans=0\ndef dfs(start,finish):\n global ans\n # print(finish)\n if len(finish)==n:\n ans+=1\n else:\n for i in adlist[start-1]:\n if i not in finish:\n #print(i)\n #print(adlist)\n #print(finish,1)\n finish_1 = set([i]) | finish\n #print(finish_1,2)\n dfs(i,finish_1)\n\nadlist=[]\nfor h in range(n): \n adlist.append([])\nfor j in range(m):\n x=ab[j][0]\n y=ab[j][1]\n adlist[x-1].append(y)\n adlist[y-1].append(x)\nfinish=set()\nfinish.add(1)\n#print(adlist)\ndfs(1,finish)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s948124823', 's496591304'] | [3064.0, 3444.0] | [18.0, 36.0] | [699, 1047] |
p03805 | u379559362 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\n\nn, m = map(int, input().split())\nroad = [[0] * n for i in range(n)]\n\ngraph = [[] for i in range(n)]\nfor j in range(m):\n x, y = map(int, input().split())\n road[x - 1][y - 1] += 1\n road[y - 1][x - 1] += 1\n graph[x-1].append(y-1)\n graph[y-1].append(x-1)\n#print(road)\n#print(graph)\n\ncount = 0\n\nfor can in itertools.permutations(range(n)):\n if can[0] != 0:\n break\n# print(can)\n plus = 1\n for k in range(n-1):\n# print(road[can[k]][can[k + 1]])\n plus *= road[can[k]][can[k + 1]]\n count += plus\n\n\ndef dfs(node, prev, visited):\n visited.append(node)\n if len(visited) == n:\n return 1\n\n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n if edge in visited:\n continue\n res += dfs(edge, prev, visited)\n\n return res\n\ndfs = dfs(0, -1, [])\n\nif count == dfs:\n print(dfs)\n', 'import itertools\n\nn, m = map(int, input().split())\nroad = [[0] * n for i in range(n)]\n\ngraph = [[] for i in range(n)]\nfor j in range(m):\n x, y = map(int, input().split())\n road[x - 1][y - 1] += 1\n road[y - 1][x - 1] += 1\n graph[x - 1].append(y - 1)\n graph[y - 1].append(x - 1)\n# print(road)\n# print(graph)\n\ncount = 0\n\nfor can in itertools.permutations(range(n)):\n if can[0] != 0:\n break\n # print(can)\n plus = 1\n for k in range(n - 1):\n # print(road[can[k]][can[k + 1]])\n plus *= road[can[k]][can[k + 1]]\n count += plus\n\n\ndef dfs(node, prev, visited):\n visited.append(node)\n if len(visited) == n:\n return 1\n\n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n if edge in visited:\n continue\n res += dfs(edge, prev, visited[:])\n\n return res\n\n\ndfs = dfs(0, -1, [])\n\nif count == dfs:\n print(dfs)\n'] | ['Wrong Answer', 'Accepted'] | ['s241092502', 's631717092'] | [3064.0, 3064.0] | [30.0, 41.0] | [905, 922] |
p03805 | u390727364 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(g, seen, n, ans):\n all_seen = True\n\n for si in seen:\n if si == False:\n all_seen = False\n\n if all_seen:\n ans += 1\n return ans\n\n for m in g[n]:\n if seen[m]:\n continue\n\n seen[m] = True\n ans = dfs(g, seen, m, ans)\n seen[m] = False\n\n return ans\n\n\ndef main():\n n, m = map(int, stdin.readline().split())\n ab = [map(int, stdin.readline().split()) for _ in range(n)]\n g = [[] for _ in range(n)]\n for abi in ab:\n a, b = abi\n g[a - 1].append(b - 1)\n g[b - 1].append(a - 1)\n seen = [False for _ in range(n)]\n seen[0] = True\n\n ans = 0\n\n ans = dfs(g, seen, 0, ans)\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'def dfs(g, seen, n):\n all_seen = True\n\n for si in seen:\n if si == False:\n all_seen = False\n\n if all_seen:\n return 1\n\n ans = 0\n\n for m in g[n]:\n if seen[m]:\n continue\n\n seen[m] = True\n ans += dfs(g, seen, m)\n seen[m] = False\n\n return ans\n\n\ndef main():\n n, m = map(int, stdin.readline().split())\n ab = [map(int, stdin.readline().split()) for _ in range(n)]\n g = [[] for _ in range(n)]\n for abi in ab:\n a, b = abi\n g[a - 1].append(b - 1)\n g[b - 1].append(a - 1)\n seen = [False for _ in range(n)]\n seen[0] = True\n\n ans = dfs(g, seen, 0)\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'from sys import stdin\n\n\ndef dfs(g, seen, n):\n all_seen = True\n\n for si in seen:\n if si == False:\n all_seen = False\n\n if all_seen:\n return 1\n\n ans = 0\n\n for m in g[n]:\n if seen[m]:\n continue\n\n seen[m] = True\n ans += dfs(g, seen, m)\n seen[m] = False\n\n return ans\n\n\ndef main():\n n, m = map(int, stdin.readline().split())\n ab = [map(int, stdin.readline().split()) for _ in range(m)]\n g = [[] for _ in range(n)]\n for abi in ab:\n a, b = abi\n g[a - 1].append(b - 1)\n g[b - 1].append(a - 1)\n seen = [False for _ in range(n)]\n seen[0] = True\n\n ans = dfs(g, seen, 0)\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s499821726', 's917800470', 's297652111'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 26.0] | [746, 713, 737] |
p03805 | u390958150 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m = map(int,input().split())\ngraph = [[0]*(n) for i in range(n)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n graph[a-1][b-1] = graph[b-1][a-1] = 1\n\nprint(graph)\nvisited = [True] + [False]*(n-1)\nans = 0\n\n\ndef dfs(x):\n global ans\n global visited\n \n if all(visited):\n ans += 1\n return\n \n \n for j in [j for j,v2 in enumerate(graph[x]) if v2 == 1 and not visited[j]]:\n visited[j] = True\n dfs(j)\n visited[j] = False\n\ndfs(0)\nprint(ans)', 'n,m = map(int,input().split())\ngraph = [[0]*(n) for i in range(n)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n graph[a-1][b-1] = graph[b-1][a-1] = 1\n\n\nvisited = [True] + [False]*(n-1)\nans = 0\n\n\ndef dfs(x):\n global ans\n global visited\n \n if all(visited):\n ans += 1\n return\n \n \n for j in [j for j,v2 in enumerate(graph[x]) if v2 == 1 and not visited[j]]:\n visited[j] = True\n dfs(j)\n visited[j] = False\n\ndfs(0)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s692796947', 's757128440'] | [3064.0, 3064.0] | [33.0, 33.0] | [505, 493] |
p03805 | u408760403 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M=map(int,input().split())\ntbl=[[0]*(N+1) for _ in range(N+1)]\nfor i in range(M):\n a,b=map(int,input().split())\n tbl[a][b]=1\n tbl[b][a]=1 \ndef dfs(s,visited):\n if len(visited)==N:\n return 1\n \n ans=0\n for i in range(1,N+1):\n if i==s: continue \n if tbl[s][i]==1 and (i not in visited):\n visited.append(i)\n ans+=dfs(i,visited)\n visited.pop()\u3000\u3000\u3000\u3000\u3000\n return ans \n\nanswer=dfs(1,[1,])\nprint(answer)\n ', 'N,M=map(int,input().split())\ntbl=[[0]*(N+1) for _ in range(N+1)]\nfor i in range(M):\n a,b=map(int,input().split())\n tbl[a][b]=1\n tbl[b][a]=1 \ndef dfs(s,visited):\n if len(visited)==N:\n return 1\n \n ans=0\n for i in range(1,N+1):\n if i==s: continue \n if tbl[s][i]==1 and (i not in visited):\n visited.append(i)\n ans+=dfs(i,visited)\n visited.pop() \n return ans \n\nanswer=dfs(1,[1,])\nprint(answer)\n '] | ['Runtime Error', 'Accepted'] | ['s014879902', 's711279818'] | [3064.0, 3064.0] | [18.0, 34.0] | [569, 552] |
p03805 | u414920281 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nn,m=map(int,input().split())\npath=[[False]*n for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1\n b-=1\n path[a][b]=True\n path[b][a]=True\nans=0;\n\nfor i in itertools.permutations(range(n),n):\n if i[0]==0:\n for j in range(n):\n if j==n-1:\n ans+=1\n break\n if not path[i[j]][i[j]+1]:\n break\nprint(ans)', 'def dfs(a,count,seen):\n nseen=seen[:]\n ans=0\n nseen[a] = 1;\n if count==n-1:\n return 1\n else:\n for i in g[a]:\n if not seen[i]:\n ans+=dfs(i,count+1,nseen)\n return ans\nn,m=map(int,input().split())\ng=[[]*n for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1\n b-=1\n g[a].append(b)\n g[b].append(a)\nseen=[0]*n\nprint(dfs(0,0,seen))\n'] | ['Runtime Error', 'Accepted'] | ['s233435306', 's501515767'] | [3064.0, 3064.0] | [25.0, 24.0] | [426, 423] |
p03805 | u426108351 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def lensetlist(A):\n B = []\n for i in A:\n if i not in B:\n B.append(i)\n return len(B)\n\nN, M = map(int, input().split())\nA = []\nB = []\n\nfor i in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nfor i in range(M):\n A.append(B[i])\n B.append(A[i])\n\nresult = []\nstack = []\nans = 0\ncount = 0\ndef path(start, visited):\n count += 1\n if count > 10000:\n break\n if len(visited) == N:\n result.append(visited[:])\n exit\n stack.append(start)\n while len(stack) > 0:\n nextpoint = stack.pop()\n if nextpoint in visited:\n continue\n visited.append(nextpoint)\n for i in range(2*M):\n if A[i] == start:\n path(B[i], visited)\n visited.pop()\n\npath(1, [])\nprint(lensetlist(result))\n', 'def lensetlist(A):\n B = []\n for i in A:\n if i not in B:\n B.append(i)\n return len(B)\n\nN, M = map(int, input().split())\nA = []\nB = []\n\nfor i in range(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nfor i in range(M):\n A.append(B[i])\n B.append(A[i])\nprint(A)\nprint(B)\nused = [0 for i in range(N)]\nresult = []\nstack = []\nans = 0\ndef path(start, visited):\n if len(visited) == N:\n result.append(visited[:])\n exit\n stack.append(start)\n while len(stack) > 0:\n nextpoint = stack.pop()\n if nextpoint in visited:\n continue\n visited.append(nextpoint)\n for i in range(2*M):\n if A[i] == start:\n path(B[i], visited)\n visited.pop()\n\npath(1, [])\nprint(lensetlist(result))\n', 'N, M = map(int, input().split())\nA = []\nB = []\n\nfor i in xrange(M):\n a, b = map(int, input().split())\n A.append(a)\n B.append(b)\nfor i in xrange(M):\n A.append(B[i])\n B.append(A[i])\n\nresult = []\nstack = []\n\ndef path(start, visited):\n if len(visited) >= N:\n if visited not in result:\n result.append(visited[:])\n exit\n stack.append(start)\n if len(stack) > 0:\n nextpoint = stack.pop()\n if nextpoint not in visited:\n visited.append(nextpoint)\n for i in xrange(2*M):\n if A[i] == start:\n path(B[i], visited)\n visited.pop()\n\npath(1, [])\nprint(len(result))\n', 'N, M = map(int, input().split())\nA = [list(map(int, input().split())) for i in range(M)]\n\nresult = []\nstack = []\n\ndef path(start, visited):\n if len(visited) >= N:\n result.append(visited[:])\n exit\n stack.append(start)\n if len(stack) > 0:\n nextpoint = stack.pop()\n if nextpoint not in visited:\n visited.append(nextpoint)\n for i in range(M):\n if A[i][0] == start:\n path(A[i][1], visited)\n if A[i][1] == start:\n path(A[i][0], visited)\n visited.pop()\n\npath(1, [])\nresult = list(map(list, set(map(tuple, result))))\nprint(len(result))\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s683140295', 's690029680', 's981123985', 's431271110'] | [3064.0, 8308.0, 3064.0, 9844.0] | [17.0, 2104.0, 17.0, 159.0] | [823, 808, 677, 666] |
p03805 | u431981421 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(i):\n global count\n global seen\n global G\n\n print(seen)\n end = True\n for n in range(N):\n if seen[n] == 0 and n != i:\n end = False\n\n if (end):\n count += 1\n return\n\n seen[i] = 1\n for g in G:\n if g[0] == i:\n if seen[g[1]] == 1:\n continue\n dfs(g[1])\n \n if g[1] == i:\n if seen[g[0]] == 1:\n continue\n dfs(g[0])\n\n seen[i] == 0\n\nN, M = map(int, input().split())\nli = [list(map(int, input().split())) for n in range(M)]\n\nG = []\n\nfor i in li:\n G.append([i[0]-1, i[1]-1])\n\ncount = 0\nseen = [0] * N\ndfs(0)\n\nprint(count)', 'def dfs(i):\n global count\n global seen\n global G\n\n end = True\n for n in range(N):\n if seen[n] == 0 and n != i:\n end = False\n\n if (end):\n count += 1\n return\n\n seen[i] = 1\n for g in G:\n if g[0] == i:\n if seen[g[1]] == 1:\n continue\n dfs(g[1])\n \n if g[1] == i:\n if seen[g[0]] == 1:\n continue\n dfs(g[0])\n\n seen[i] = 0\n\nN, M = map(int, input().split())\nli = [list(map(int, input().split())) for n in range(M)]\n\nG = []\n\nfor i in li:\n G.append([i[0]-1, i[1]-1])\n\ncount = 0\nseen = [0] * N\ndfs(0)\n\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s710448017', 's106011430'] | [3064.0, 3064.0] | [17.0, 57.0] | [580, 565] |
p03805 | u437351386 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=list(map(int,input().split()))\n\nimport sys\nsys.setrecursionlimit(10**7)\n\n\nes=[[0 for i in range(n)] for j in range(n)]\nfor i in range(m):\n a,b=list(map(int,input().split()))\n es[a-1][b-1]=1\n es[b-1][a-1]=1\n\n \n\n\ndef dfs(v,visited):\n ans=0\n \n \n visited[v-1]=1\n print(visited)\n \n if visited==check:\n visited[v-1]=0\n return 1\n \n \n for i in range(n):\n \n if visited[i]==0 and es[v-1][i]==1:\n ans=ans+dfs(i+1,visited)\n \n visited[v-1]=0\n \n return ans\n\n\n\n\n\nvisited=[0 for i in range(n)]\ncheck=[1 for i in range(n)]\nprint(dfs(1,visited))\n\n\n\n\n\n\n \n\n ', 'n,m=list(map(int,input().split()))\n\nes=[[0 for i in range(n)] for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n es[a-1][b-1]=1\n es[b-1][a-1]=1\n\n\nimport sys\nsys.setrecursionlimit(10**7)\n\n\n\n\nvisited=[0 for i in range(n)]\ncheck=[1 for i in range(n)]\n\ndef dfs(v,visited):\n \n ans=0\n \n visited[v-1]=1\n\n if visited==check:\n visited[v-1]=0\n return 1\n \n for i in range(n):\n \n if es[v-1][i]==1 and visited[i]==0:\n ans+=dfs(i+1,visited)\n \n visited[v-1]=0\n return ans\n\nprint(dfs(1,visited))\n'] | ['Wrong Answer', 'Accepted'] | ['s421837791', 's970261687'] | [9232.0, 9144.0] | [47.0, 36.0] | [892, 969] |
p03805 | u440129511 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import networkx as nx\nn,m=map(int,input().split())\ns=[list(map(int,input().split())) for _ in range(m)]\ng=nx.Graph()\ng.add_edges_from(s)\n\n\nl=[[] for _ in range(n)]\nfor i in range(m):\n a,b=s[i][0],s[i][1]\n l[a-1].append(b)\n l[b-1].append(a)\n\nl1=sum(l, []) \nl1.insert(0,1)\nl_depth=list(dict.fromkeys(l1))\n\n\nk=list(nx.all_simple_paths(G, source=1, target=l_depth[-1]))\n\nc=0\nma=0\nfor i in range(k):\n if len(k[i])>ma:\n ma=len(k[i])\n c-=c+1\n elif len(k[i])==ma:\n c+=1\nprint(c)', 'import networkx as nx\nn,m=map(int,input().split())\ns=[list(map(int,input().split())) for _ in range(m)]\ng=nx.Graph()\ng.add_edges_from(s)\n \n\nl=[[] for _ in range(n)]\nfor i in range(m):\n a,b=s[i][0],s[i][1]\n l[a-1].append(b)\n l[b-1].append(a)\n\nl1=sum(l, []) \nl1.insert(0,1)\nl_depth=list(dict.fromkeys(l1))\n \n\nk=list(nx.all_simple_paths(G, source=1, target=l_depth[-1]))\n \nc=0\nma=0\nfor i in range(len(k)):\n if len(k[i])>ma:\n ma=len(k[i])\n c-=c+1\n elif len(k[i])==ma:\n c+=1\nprint(c)', 'import networkx as nx\nn,m=map(int,input().split())\ns=[list(map(int,input().split())) for _ in range(m)]\ng=nx.Graph()\ng.add_edges_from(s)\n \n\nl=[[] for _ in range(n)]\nfor i in range(m):\n a,b=s[i][0],s[i][1]\n l[a-1].append(b)\n l[b-1].append(a)\n\nl1=sum(l, []) \nl1.insert(0,1)\nl_depth=list(dict.fromkeys(l1))\n \n\nk=list(nx.all_simple_paths(g, source=1, target=l_depth[-1]))\n \nc=0\nma=0\nfor i in range(len(k)):\n if len(k[i])>ma:\n ma=len(k[i])\n c-=c+1\n if len(k[i])==ma:\n c+=1\nprint(c)', 'import networkx as nx\nn,m=map(int,input().split())\ns=[list(map(int,input().split())) for _ in range(m)]\ng=nx.Graph()\ng.add_edges_from(s)\n \n\nl=[[] for _ in range(n)]\nfor i in range(m):\n a,b=s[i][0],s[i][1]\n l[a-1].append(b)\n l[b-1].append(a)\n\nl1=sum(l, []) \nl1.insert(0,1)\nl_depth=list(dict.fromkeys(l1))\n \n\nk=list(nx.all_simple_paths(g, source=1, target=l_depth[-1]))\n \nc=0\nma=0\nfor i in range(len(k)):\n if len(k[i])>ma:\n ma=len(k[i])\n c-=c+1\n elif len(k[i])==ma:\n c+=1\nprint(c)', 'n,m=map(int,input().split())\ns=[list(map(int,input().split())) for _ in range(m)]\n\n\nl=[[] for _ in range(n)]\nfor i in range(m):\n a,b=s[i][0],s[i][1]\n l[a-1].append(b)\n l[b-1].append(a)\n\ndef dfs(now, prev, visited):\n visited.append(now)\n if len(visited) == n:\n return 1\n \n ret = 0 \n for edge in l[now-1]:\n if edge == prev:\n continue\n if edge in visited:\n continue\n \n ret += dfs(edge, prev, visited[:])\n \n return ret \n\nprint(dfs(1, 0, []))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s340076308', 's432871510', 's694684093', 's757292871', 's444048832'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [18.0, 18.0, 17.0, 18.0, 28.0] | [728, 736, 734, 736, 856] |
p03805 | u454557108 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['# -*- coding: utf-8 -*-\nimport numpy as np\n\nn,m = map(int, input().split())\ngraph = [[0 for i in range(n)] for j in range(n)]\ngraph = np.array(graph)\n\nfor i in range(m):\n a,b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\n\nused = [False]*n\nused[0] = True\n\ndef DFS(v,used):\n if all(used):\n return 1\n ans = 0\n for i in graph(v):\n if used[i]:\n continue\n used[i] = True\n ans += DFS(i,used)\n used[i] = False\n return ans\n \nprint(DFS(0,used))', '# -*- coding: utf-8 -*-\nimport numpy as np\n\nn,m = map(int, input().split())\ngraph = [[] for j in range(n)]\ngraph = np.array(graph)\n\nfor i in range(m):\n a,b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\n\nused = [False]*n\nused[0] = True\n\ndef DFS(v,used):\n if all(used):\n return 1\n ans = 0\n for i in graph(v):\n if used[i]:\n continue\n used[i] = True\n ans += DFS(i,used)\n used[i] = False\n return ans\n \nprint(DFS(0,used))', '# -*- coding: utf-8 -*-\nn,m = map(int, input().split())\ngraph = [[] for j in range(n)]\n\nfor i in range(m):\n a,b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\n\nused = [False]*n\nused[0] = True\n\ndef DFS(v,used):\n if all(used):\n return 1\n ans = 0\n for i in graph[v]:\n if used[i]:\n continue\n used[i] = True\n ans += DFS(i,used)\n used[i] = False\n return ans\n \nprint(DFS(0,used))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s090249858', 's983263602', 's280117527'] | [27148.0, 26984.0, 9212.0] | [111.0, 113.0, 31.0] | [532, 513, 469] |
p03805 | u463858127 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import sys\nsys.setrecursionlimit(10**20)\n\nN, M = map(int, input().split())\n\nMap = [[] for _ in range(M)]\nreached = [False]*N\n\nfor _ in range(M):\n aa, bb = map(int, input().split())\n Map[aa-1].append(bb-1)\n Map[bb-1].append(aa-1)\n\ncnt = 0\n\ndef DFS(x):\n global cnt\n reached[x] = True\n\n if all(reached):\n cnt += 1\n\n for i in range(N):\n if reached[i]:\n continue\n\n if i in Map[x]:\n DFS(i)\n\n reached[x] = False\n return\n\nDFS(0)\nprint(cnt)\n', 'N, M = map(int, input().split())\n\nMap = [[] for _ in range(N)]\nreached = [False]*N\n\nfor _ in range(M):\n aa, bb = map(int, input().split())\n Map[aa-1].append(bb-1)\n Map[bb-1].append(aa-1)\n\ncnt = 0\n\ndef DFS(x):\n global cnt\n global reached\n\n reached[x] = True\n\n if all(reached):\n cnt += 1\n reached[x] = False\n\n return\n\n for i in Map[x]:\n if reached[i]:\n continue\n\n else:\n DFS(i)\n\n reached[x] = False\n\n\nDFS(0)\nprint(cnt)\n'] | ['Runtime Error', 'Accepted'] | ['s126141309', 's689600860'] | [3064.0, 3064.0] | [17.0, 24.0] | [502, 501] |
p03805 | u484315555 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["\nclass Graph():\n def __init__(self):\n \n self.adjacency_dict = {}\n \n def add_vertex(self, v):\n \n self.adjacency_dict[v] = []\n def add_edge(self, v1, v2):\n \n \n self.adjacency_dict[v1].append(v2)\n self.adjacency_dict[v2].append(v1)\n def remove_edge(self, v1, v2):\n \n self.adjacency_dict[v1].remove(v2)\n self.adjacency_dict[v2].remove(v1)\n def remove_vertex(self,v):\n \n while self.adjacency_dict[v] != []:\n adjacent_vertex = self.adjacency_dict[v][-1]\n self.remove_edge(v, adjacent_vertex)\n del self.adjacency_dict[v]\n \n def print_graph(self):\n print(self.adjacency_dict)\n\n def _init_internal_graph(self, graph_dict):\n self.adjacency_dict = graph_dict\n \n def get_edge(self, v):\n \n return self.adjacency_dict[v]\n\ndef dprint(*args):\n if len(args)==1:\n print(args[0])\n else:\n print(args)\n\ndebug = False\nif debug:\n g = Graph()\n # N,M = [7, 7]\n # g._init_internal_graph({0: [2], 1: [6], 2: [0, 3], 3: [2, 4, 5], 4: [3, 5], 5: [3, 4, 6], 6: [1, 5]})\n \n N,M = [3, 3]\n g._init_internal_graph({0: [1, 2], 1: [0, 2], 2: [0, 1]})\nelse:\n N, M = map(int, input().split())\n g = Graph()\n dprint(N,M)\n\n for n in range(N):\n g.add_vertex(n)\n\n # 0-origin \n for m in range(M):\n v1,v2 = list(map(int, input().split()))\n g.add_edge(v1-1,v2-1) \n\n# g.print_graph()\n\nseen = [False] * N\ncount = 0\n\ndef dfs(node, depth):\n dprint(node,depth) \n if seen[node]:\n return 0\n if depth == N - 1:\n dprint('count-up',seen)\n return 1\n\n seen[node] = True\n dprint(seen)\n \n total_paths = 0\n for next_node in g.get_edge(node):\n total_paths += dfs(next_node, depth + 1)\n\n \n seen[node] = False\n\n return total_paths\n\ncount = dfs(0, 0)\nprint(count)\n", "class Graph():\n def __init__(self):\n \n self.adjacency_dict = {}\n \n def add_vertex(self, v):\n \n self.adjacency_dict[v] = []\n def add_edge(self, v1, v2):\n \n \n self.adjacency_dict[v1].append(v2)\n self.adjacency_dict[v2].append(v1)\n def remove_edge(self, v1, v2):\n \n self.adjacency_dict[v1].remove(v2)\n self.adjacency_dict[v2].remove(v1)\n def remove_vertex(self,v):\n \n while self.adjacency_dict[v] != []:\n adjacent_vertex = self.adjacency_dict[v][-1]\n self.remove_edge(v, adjacent_vertex)\n del self.adjacency_dict[v]\n \n def print_graph(self):\n print(self.adjacency_dict)\n\n def _init_internal_graph(self, graph_dict):\n self.adjacency_dict = graph_dict\n \n def get_edge(self, v):\n \n return self.adjacency_dict[v]\n\ndef dprint(*args):\n if debug:\n if len(args)==1:\n print(args[0])\n else:\n print(args)\n\ndebug = False\nif debug:\n g = Graph()\n # N,M = [7, 7]\n # g._init_internal_graph({0: [2], 1: [6], 2: [0, 3], 3: [2, 4, 5], 4: [3, 5], 5: [3, 4, 6], 6: [1, 5]})\n \n N,M = [3, 3]\n g._init_internal_graph({0: [1, 2], 1: [0, 2], 2: [0, 1]})\nelse:\n N, M = map(int, input().split())\n g = Graph()\n dprint(N,M)\n\n for n in range(N):\n g.add_vertex(n)\n\n # 0-origin \n for m in range(M):\n v1,v2 = list(map(int, input().split()))\n g.add_edge(v1-1,v2-1) \n\n# g.print_graph()\n\nseen = [False] * N\ncount = 0\n\ndef dfs(node, depth):\n dprint(node,depth) \n if seen[node]:\n return 0\n if depth == N - 1:\n dprint('count-up',seen)\n return 1\n\n seen[node] = True\n dprint(seen)\n \n total_paths = 0\n for next_node in g.get_edge(node):\n total_paths += dfs(next_node, depth + 1)\n\n \n seen[node] = False\n\n return total_paths\n\ncount = dfs(0, 0)\nprint(count)\n"] | ['Wrong Answer', 'Accepted'] | ['s142246284', 's128452097'] | [4340.0, 3192.0] | [129.0, 38.0] | [2299, 2318] |
p03805 | u492447501 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N-1 or cur_node <= 0 or cur_node >= N-1:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\nmap[N-1] = True\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N-1:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\nmap[N-1] = True\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\n\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N-1 or cur_node <= 0 or cur_node >= N:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n dfs(cur_node+1, cur_node, Node_num+1, map, l)\n dfs(cur_node-1, cur_node, Node_num+1, map, l)\n\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True or map[pre_node]==True:\n return\n \n print(pre_node)\n print(cur_node)\n map[cur_node]=True\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(M):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n lst[idx2-1][idx1-1] = 1\n\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N-1:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\nmap[N-1] = True\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N-1:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n print(pre_node)\n print(cur_node)\n map[cur_node]=True\n for i in range(N):\n if i != cur_node and map[pre_node] == True:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(M):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n lst[idx2-1][idx1-1] = 1\n\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n print(cur_node)\n print(pre_node)\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N-1:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N-1:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N or cur_node <= 0 or cur_node >= N:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\n\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N-1:\n graph_count = graph_count + 1\n\nprint(graph_count)\n\n', 'import copy\ndef dfs(cur_node, pre_node, Node_num, map, l):\n \n\n if Node_num == N-1 or cur_node <= 0 or cur_node >= N-1:\n return\n elif l[pre_node][cur_node]==0: \n return\n elif map[cur_node]==True:\n return\n\n map[cur_node]=True\n\n for i in range(N):\n if i != cur_node:\n dfs(i, cur_node, Node_num+1, map, l)\n\n\nS = input()\nS = list(map(int, S.split()))\n\nN = S[0]\nM = S[1]\n\n\nmap = [False]*N\nmap[0] = True\nmap[N-1] = True\nlst = []\n\nfor i in range(N):\n lst.append([0]*N)\n\nfor i in range(N):\n S = input()\n S = list(S.split())\n idx1 = int(S[0])\n idx2 = int(S[1])\n lst[idx1-1][idx2-1] = 1\n\ngraph_count = 0\n\nfor i in range(1, N, 1):\n map_copy = copy.copy(map)\n lst_copy = copy.copy(lst)\n\n dfs(i, 0, 0, map_copy, lst_copy)\n count = 0\n for i in map_copy:\n if i == True:\n count = count + 1\n if count == N-1:\n graph_count = graph_count + 1\n\nprint(graph_count)\n', 'import copy\n\nN,M = map(int, input().split())\n\nV = []\n\ndef dfs(node, seen):\n\n if seen[node]==True:\n return 0\n\n seen[node] = True\n if not(False in seen):\n return 1\n ret = 0\n for next_node in V[node]:\n ret += dfs(next_node, copy.deepcopy(seen))\n return ret\n\nfor _ in range(N):\n V.append(set())\n\nfor _ in range(M):\n a,b = map(int, input().split())\n V[a-1].add(b-1)\n V[b-1].add(a-1)\n\nprint(dfs(0, copy.deepcopy([False]*N)))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s128626213', 's166825589', 's188742968', 's334603731', 's413207918', 's468061684', 's539978726', 's832400804', 's868576848', 's967351072', 's630338603'] | [3444.0, 3444.0, 3444.0, 3444.0, 3444.0, 3444.0, 3444.0, 3444.0, 3444.0, 3956.0, 3444.0] | [22.0, 22.0, 23.0, 22.0, 22.0, 22.0, 22.0, 22.0, 22.0, 39.0, 496.0] | [1031, 1029, 1016, 1112, 1031, 1107, 1053, 1016, 1015, 1033, 469] |
p03805 | u500297289 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["import sys\nsys.setrecursionlimit(1000000)\n\nN, M = map(int, input().split())\nedge = [[] for _ in range(N + 1)]\nab = [list(map(int, input().split())) for _ in range(M)]\nfor i in range(M):\n a, b = ab[i][0], ab[i][1]\n edge[a].append(b)\n edge[b].append(a)\n\n\ndef f(now, v):\n v = v & (1 << now)\n for to in edge[now]:\n if v >> to == 0:\n f(to, v)\n if v == int('0b11111111', 0):\n ans += 1\n\nans = 0\nf(1, 1)\n\nprint(ans)\n", 'import sys\nsys.setrecursionlimit(1000000)\n\nN, M = map(int, input().split())\nedge = [[] for _ in range(N + 1)]\nab = [list(map(int, input().split())) for _ in range(M)]\nfor i in range(M):\n a, b = ab[i][0] - 1, ab[i][1] - 1\n edge[a].append(b)\n edge[b].append(a)\n\nans = 0\n\ndef f(now, v):\n global ans\n v |= (1 << now)\n for to in edge[now]:\n if not (v & (1<<to)):\n f(to, v)\n if bin(v).count("1") == N:\n ans += 1\n\nf(0, 0)\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s762852481', 's619805117'] | [708980.0, 3064.0] | [1822.0, 34.0] | [451, 473] |
p03805 | u500944229 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m = map(int,input())\npath = [map(int,input()) for x in range(m)]\n\ntable = [[] for x in range(n)]\nfor x in path:\n table[int(x[0])-1].append(int(x[1])-1)\n table[int(x[1])-1].append(int(x[0])-1)\n \nimport itertools\ncount = 0\nfor z in itertools.permutations(range(0,n)):\n if z[0] == 0:\n print(z)\n for y in range(len(z)-1):\n if z[y+1] in table[z[y]]:\n continue\n else:\n count -= 1\n break\n count += 1', 'n,m = map(int,input().split())\npath = [input().split() for x in range(m)]\n\ntable = [[] for x in range(n)]\nfor x in path:\n table[int(x[0])-1].append(int(x[1])-1)\n table[int(x[1])-1].append(int(x[0])-1)\n \nimport itertools\ncount = 0\nfor z in itertools.permutations(range(0,n)):\n if z[0] == 0:\n for y in range(len(z)-1):\n if z[y+1] in table[z[y]]:\n continue\n else:\n count -= 1\n break\n count += 1\nprint(count)'] | ['Runtime Error', 'Accepted'] | ['s885173146', 's353958916'] | [3064.0, 3064.0] | [18.0, 32.0] | [494, 497] |
p03805 | u503901534 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nn,m = map(int,input().split())\nH = [[0 for _ in range(n)] for _ in range(n) ]\n\nfor _ in range(m):\n a, b = map(int,input().split())\n edge_list.append([a-1,b-1])\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\n\ndef dfs(node,visited):\n global ans\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n visited[node] = 1\n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n visited[node_] = 0\n\ndfs(0,l)\nprint(ans)', 'n,m = map(int,input().split())\nH = [[0 for _ in range(n)] for _ in range(n) ]\n\nfor _ in range(m):\n a, b = map(int,input().split())\n edge_list.append([a-1,b-1])\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\n\ndef dfs(node,visited):\n global ans\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n visited[node] = 1\n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n visited[node_] = 0\n\ndfs(0,l)\nprint(ans)', 'n,m = map(int,input().split())\nH = [[0 for _ in range(n)] for _ in range(n) ]\n\nfor _ in range(m):\n a, b = map(int,input().split())\n edge_list.append([a-1,b-1])\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\n\ndef dfs(node,visited):\n global ans\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n visited[node] = 1\n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n visited[node_] = 0 \ndfs(0,l)\nprint(ans)', 'n,m = map(int,input().split())\nH = [[0 for _ in range(n)] for _ in range(n) ]\n\nfor _ in range(m):\n a, b = map(int,input().split())\n edge_list.append([a-1,b-1])\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\n\ndef dfs(node,visited):\n global ans\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n visited[node] = 1\n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n visited[node_] = 0 \ndfs(0,l)\nprint(ans)\n', 'n,m = map(int,input().split())\n\nH = [[0 for _ in range(n)] for _ in range(n) ]\nedge_list = []\n\nfor _ in range(m):\n a, b = map(int,input().split())\n edge_list.append([a,b])\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\nl[0] = 1\n\ndef dfs(node,x):\n \n visited = x\n global ans\n visited[node] = 1\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n \n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n\n\n\ndfs(0,l)\nprint(ans)\n', 'n,m = map(int,input().split())\nH = [[0 for _ in range(n)] for _ in range(n) ]\n\nfor _ in range(m):\n a, b = map(int,input().split())\n H[a-1][b-1] = 1\n H[b-1][a-1] = 1\n \nl = [0 for _ in range(n)]\nans = 0\n\ndef dfs(node,visited):\n global ans\n if visited.count(0) == 0:\n ans += 1 \n return 0\n else:\n visited[node] = 1\n for node_,edge_ in enumerate(H[node]):\n if edge_ == 1 and visited[node_] != 1:\n visited[node_] = 1\n visited[node] = 1\n dfs(node_,visited)\n \n \n visited[node_] = 0\ndfs(0,l)\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s028982451', 's368221068', 's391444038', 's463865893', 's773711620', 's870766558'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 17.0, 17.0, 18.0, 17.0, 30.0] | [689, 642, 657, 658, 651, 665] |
p03805 | u513900925 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\nedge_list = [list() for i in range(N)]\nfor i in range(M):\n a,b = map(int,input().split())\n edge_list[a-1].append(b-1)\n edge_list[b-1].append(a-1)\ndone = [0] * n\nchk = 0\ndef dfs(s,done):\n done = done[:]\n global chk\n done[s] = True \n if all(done):\n chk += 1\n for i in edges[u]:\n if not done[i]:\n dfs(i.done)\n return 0\ndfs(0,done)\nprint(chk)', 'N,M = map(int,input().split())\nedge_list = [list() for i in range(N)]\nfor i in range(M):\n a,b = map(int,input().split())\n edge_list[a-1].append(b-1)\n edge_list[b-1].append(a-1)\ndone = [0] * N\nchk = 0\ndef dfs(s,done):\n done = done[:]\n global chk\n done[s] = True\n if all(done):\n chk += 1\n for i in edge_list[s]:\n if not done[i]:\n dfs(i,done)\n return 0\ndfs(0,done)\nprint(chk)'] | ['Runtime Error', 'Accepted'] | ['s629194471', 's959927766'] | [3064.0, 3064.0] | [18.0, 27.0] | [433, 436] |
p03805 | u516554284 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nn,m=map(int,input().split())\nrin=[[]for _ in range(n)]\nfor _ in range(m):\n a,b=map(int,input().split())\n rin[a-1].append(b-1)\n rin[b-1].append(a-1)\n \nli=[ i for i in range(1,n+1)]\n\nans=0\n\nfor v in itertools.permutations(li):\n pas=0\n ch=0\n st=1\n for x in range(n-1):\n if v[x]-1 not in rin[st-1]:\n ch+=1\n break\n else:\n st=v[x]\n if ch==0:\n ans+=1\n \nprint(ans)', 'import itertools\n\nn,m=map(int,input().split())\nrin=[[]for _ in range(n)]\nfor _ in range(m):\n a,b=map(int,input().split())\n rin[a-1].append(b-1)\n rin[b-1].append(a-1)\n \nli=[ i for i in range(2,n+1)]\n\nans=0\n\nfor v in itertools.permutations(li):\n pas=0\n ch=0\n st=1\n for x in range(n-1):\n if v[x]-1 not in rin[st-1]:\n ch+=1\n break\n else:\n st=v[x]\n if ch==0:\n ans+=1\n \nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s361805166', 's590974092'] | [9060.0, 9136.0] | [94.0, 35.0] | [410, 410] |
p03805 | u517910772 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def abc054_c_one_stroke_paths():\n import copy\n N, E = map(int, input().split())\n\n # create graph G\n G = {}\n for n in range(N):\n a, z = map(int, input().split())\n G[a] = G.get(a, [])\n G[a].append(z)\n G[z] = G.get(z, [])\n G[z].append(a)\n\n print(G)\n\n # find all paths\n if G.get(1) is None:\n print(0)\n return\n\n paths = []\n\n def solve(a, path):\n path.append(a)\n if len(path) == N:\n paths.append(path)\n return\n for z in G.get(a):\n p = copy.copy(path)\n print(p, a, z)\n if z in p:\n continue\n solve(z, p)\n\n solve(1, [])\n print(paths, len(paths))\n\n\n##########\nif __name__ == "__main__":\n abc054_c_one_stroke_paths()\n', 'def abc054_c_one_stroke_paths():\n import copy\n N, E = map(int, input().split())\n\n # create graph G\n G = {}\n for m in range(M):\n a, z = map(int, input().split())\n G[a] = G.get(a, [])\n G[a].append(z)\n G[z] = G.get(z, [])\n G[z].append(a)\n\n # print(G)\n\n # find all paths\n if G.get(1, 0) == 0:\n print(0)\n return\n\n paths = []\n\n def solve(a, path):\n path.append(a)\n if len(path) == N:\n paths.append(path)\n return\n for z in G.get(a):\n p = copy.copy(path)\n if z in p:\n continue\n solve(z, p)\n\n solve(1, [])\n # print(paths)\n print(len(paths))\n\n\n##########\nif __name__ == "__main__":\n abc054_c_one_stroke_paths()\n', 'def abc054_c_one_stroke_paths():\n N, M = map(int, input().split())\n\n # create graph G\n G = {}\n for m in range(M):\n a, z = map(int, input().split())\n G[a] = G.get(a, [])\n G[a].append(z)\n G[z] = G.get(z, [])\n G[z].append(a)\n\n # print(G)\n\n # find all paths\n if G.get(1, 0) == 0:\n print(0)\n return\n\n def dfs(a, path):\n path.append(a)\n if len(path) == N:\n return 1\n\n paths = 0\n for z in G.get(a):\n if z in path:\n continue\n paths += dfs(z, path[:])\n\n return paths\n\n print(dfs(1, []))\n\n\n##########\nif __name__ == "__main__":\n abc054_c_one_stroke_paths()\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s238694906', 's956208555', 's993156111'] | [3444.0, 3444.0, 3064.0] | [22.0, 22.0, 28.0] | [796, 783, 709] |
p03805 | u524534026 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import sys\nimport itertools\nn,m=map(int,input().split())\nab=[]\nfor _ in range(m):\n ab.append(list(map(int,input().split())))\n\nlis=[i for i in range(1,n+1)]\nper_lis = itertools.permutations(lis) \n\nans=0\nfor one_case in per_lis:\n if one_case[0]==1:\n tmp=0\n for j in range(n-1):\n for num in ab:\n if one_case[j]==num[0] and one_case[j+1]==num[1]:\n tmp+=1\n break \n if tmp==n-1:\n ans+=1\n\nprint(ans)', 'import sys\nimport itertools\nn,m=map(int,input().split())\nab=[]\nfor _ in range(m):\n ab.append(list(map(int,input().split())))\n\nlis=list(range(1,n+1))\nper_lis =[i for i in list(itertools.permutations(lis)) if i[0]==1]\n\nans=0\n\nfor one_case in per_lis:\n tmp=0\n for j in range(n-1):\n for num in ab:\n if one_case[j]==num[0] and one_case[j+1]==num[1]:\n tmp+=1\n elif one_case[j]==num[1] and one_case[j+1]==num[0]:\n tmp+=1\n \n\n if tmp==n-1:\n ans+=1\n\nprint(ans)\n\n \n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s259813825', 's543310324'] | [3064.0, 8052.0] | [117.0, 288.0] | [501, 568] |
p03805 | u538381753 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["n, m = [int(x) for x in input().split(' ')]\n\nedges = set([tuple(input().split(' ')) for _ in range(n)])\nedges.update([(x[1], x[0]) for x in list(edges)])\n\n\ndef dfs(node, history):\n ans = 0\n if len(history) == n - 1:\n print(history)\n return 1\n\n nextnodes = [\n x[1] for x in edges if x[1] not in history and x[0] == node and x[1] != node\n ]\n history.add(node)\n for next in nextnodes:\n ans += dfs(next, history)\n history.remove(node)\n return ans\n\n\nprint(dfs('1', set()))\n", "n, m = [int(x) for x in input().split(' ')]\n \nedges = set([tuple(input().split(' ')) for _ in range(m)])\nedges.update([(x[1], x[0]) for x in list(edges)])\n \n \ndef dfs(node, history):\n ans = 0\n if len(history) == n - 1:\n return 1\n \n nextnodes = [\n x[1] for x in edges if x[1] not in history and x[0] == node and x[1] != node\n ]\n history.add(node)\n for next in nextnodes:\n ans += dfs(next, history)\n history.remove(node)\n return ans\n \n \nprint(dfs('1', set()))"] | ['Runtime Error', 'Accepted'] | ['s222734065', 's552353134'] | [3064.0, 3064.0] | [19.0, 61.0] | [520, 502] |
p03805 | u547167033 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nn,m=map(int,input().split())\ng=[[] for i in range(n)]\nfor _ in range(m):\n u,v=map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\nans=0\nfor v in permutations([int(i) for i in range(n)],n):\n for i in range(n-1):\n if not v[i+1] in g[v[i]]:\n break\n else:\n ans+=1\nprint(ans)', 'from itertools import permutations\nn,m=map(int,input().split())\ng=[[] for i in range(n)]\nfor _ in range(m):\n u,v=map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\nans=0\nfor v in permutations([int(i) for i in range(n)],n):\n if v[0]!=0:\n continue\n for i in range(n-1):\n if not v[i+1] in g[v[i]]:\n break\n else:\n ans+=1\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s531609089', 's251927286'] | [3064.0, 3064.0] | [98.0, 33.0] | [334, 361] |
p03805 | u548545174 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import sys\nsys.setrecursionlimit(1000000)\n\nN, M = map(int, input().split())\nab = [list(map(int, input().split())) for _ in range(M)]\nfor j in ab:\n if j[::-1] not in ab:\n ab.append(j[::-1])\n\nans = 0\n\n#idx = [_ for _ in ab if _[0] == 1]\n#idx = (ab.index(idx), 0)\n\nsearched = [0] * N\nsearched[0] = 1\nlength = 0\n\ndef dfs(n):\n \n global ans, length\n if length > N - 1:\n return\n if sum(searched) == N:\n ans += 1\n return\n idx = [_ for _ in ab if _[0] == n]\n for idx in idx:\n id1, _ = (ab.index(idx), 0)\n next = ab[id1][1]\n searched[next - 1] = 1\n length += 1\n \n dfs(next)\n\ndfs(1)\nprint(ans)', 'N, M = map(int, input().split())\n\n\n\nnei_L = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n nei_L[a - 1].append(b - 1)\n nei_L[b - 1].append(a - 1)\n\nans = 0\nvisited = [0] * N\n\ndef dfs(now=0):\n global visited, ans\n visited[now] = 1\n if all(visited):\n ans += 1\n # visited = [0] * N\n else:\n cand = nei_L[now]\n for c in cand:\n if not visited[c]:\n dfs(c)\n visited[now] = 0\n\ndfs()\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s107677794', 's824375937'] | [3064.0, 3064.0] | [17.0, 25.0] | [669, 572] |
p03805 | u552738814 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\nedges = {i:[] for i in range(1,M+1)}\nfor i in range(M):\n a,b = map(int,input().split())\n edges[a].append(b)\n edges[b].append(a)\n\n\ndef dfs(list):\n \n if len(list) == N:\n return 1\n else:\n x = list[-1]\n \n \n next = [n for n in edges[x] if n not in list]\n \n if len(next) == 0:\n return 0\n\n total = 0\n \n for n in next:\n total += dfs(list + [n])\n\n return total', 'N,M = map(int,input.split())\n\n\n\nedges = {i:[] for i in range(1,N+1)}\nfor i in range(M):\n a,b = [int(a) for a in input().split()]\n edges[a].append(b)\n edges[b].append(a)\n\n\n\ndef dfs(list):\n \n if len(list) == N:\n return 1\n else:\n a = list[-1]\n \n \n next = [n for n in edges[a] if n not in list]\n \n if len(next) == 0:\n return 0\n\n total = 0\n \n for n in next:\n total += dfs(list + [n])\n\n return total\n\n\nans = dfs([1])\n\nprint(ans)\n', 'N,M = map(int,input().split())\n\n\n\nedges = {i:[] for i in range(1,N+1)}\nfor i in range(M):\n a,b = map(int,input().split())\n edges[a].append(b)\n edges[b].append(a)\n\n\n\ndef dfs(list):\n \n if len(list) == N:\n return 1\n else:\n a = list[-1]\n \n \n next = [n for n in edges[a] if n not in list]\n \n if len(next) == 0:\n return 0\n\n total = 0\n \n for n in next:\n total += dfs(list + [n])\n\n return total\n\n\nans = dfs([1])\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s319398602', 's625726331', 's825708443'] | [9096.0, 9148.0, 9204.0] | [27.0, 28.0, 40.0] | [832, 861, 854] |
p03805 | u557282438 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nN,M = map(int,input().split())\nab = [list(map(int,input().split())) for i in range(M)]\nr = list(range(1,N+1))\nok = 1\ncnt = 0\nfor v in itertools.permutations(r):\n if(v[0] == 1):\n ok = 1\n for i in range(N-1):\n if(list(v[i:i+2]) not in ab and list(reversed(v[i:i+2])) not in ab):\n ok = 0\n break\n print(ok,v)\n if(ok == 1):\n cnt += 1\nprint(cnt)', 'import itertools\nN,M = map(int,input().split())\nab = [list(map(int,input().split())) for i in range(M)]\nr = list(range(1,N+1))\nok = 1\ncnt = 0\nfor v in itertools.permutations(r):\n if(v[0] == 1):\n ok = 1\n for i in range(N-1):\n if(list(v[i:i+2]) not in ab and list(reversed(v[i:i+2])) not in ab):\n ok = 0\n break\n if(ok == 1):\n cnt += 1\nprint(cnt)'] | ['Wrong Answer', 'Accepted'] | ['s230891206', 's266087670'] | [3316.0, 3064.0] | [86.0, 74.0] | [439, 419] |
p03805 | u557494880 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\nG = [[] for i in range(N+1)]\nfor i in range(M):\n a,b = map(int,input().split())\n G[a].append(b)\n G[b].append(a)\nl = [i for i in range(2,N+1)]\nimport itertools\nans = 0\nfor v in itertools.permutations(l):\n s = 1\n t = 1\n while v:\n s = t\n t = v.pop(0)\n if t not in G[s]:\n break\n if len(v) == 0:\n ans += 1\nprint(ans)', 'N,M = map(int,input().split())\nG = [[] for i in range(N+1)]\nfor i in range(M):\n a,b = map(int,input().split())\n G[a].append(b)\n G[b].append(a)\nl = [i for i in range(2,N+1)]\nimport itertools\nans = 0\nfor v in itertools.permutations(l):\n v = list(v)\n flag = 1\n s = 1\n t = 1\n while v:\n s = t\n t = v.pop(0)\n if t not in G[s]:\n flag = 0\n break\n ans += flag\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s265274673', 's993557517'] | [3064.0, 3064.0] | [19.0, 34.0] | [402, 431] |
p03805 | u560988566 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m = map(int, input().split())\nls = [tuple(map(int, input().split())) for _ in range(m)]\nneighborls = []\nfor i in range(1,n+1):\n neighbors = []\n for j in range(1, m+1):\n if (i,j) in ls or (j,i) in ls:\n neighbors.append(j)\n neighborls.append(neighbors)\n\nans = 0\n\ndef main():\n global ans\n visitedls = [1]\n ans = dfs(1, visitedls, ans)\n\n print(ans)\n \n \ndef dfs(a, visitedls, ans):\n global ans\n if len(visitedls) == n:\n ans += 1\n for i in range(1,n+1):\n if i not in visitedls and i in neighborls[a-1]:\n visitedls.append(i)\n ans = dfs(i, visitedls, ans)\n visitedls.remove(i)\n return ans\n\n\nif __name__ == "__main__":\n main()', 'n,m = map(int, input().split())\nls = [tuple(map(int, input().split())) for _ in range(m)]\nneighborls = []\nfor i in range(1,n+1):\n neighbors = []\n for j in range(1, m+1):\n if (i,j) in ls or (j,i) in ls:\n neighbors.append(j)\n neighborls.append(neighbors)\n\nans = 0\n\ndef main():\n visitedls = [1]\n ans = dfs(1, visitedls, ans)\n\n print(ans)\n \n \ndef dfs(a, visitedls, ans):\n if len(visitedls) == n:\n ans += 1\n return ans\n for i in range(1,n+1):\n if i not in visitedls and i in neighborls[a-1]:\n visitedls.append(i)\n ans = dfs(i, visitedls, ans)\n visitedls.remove(i)\n return ans\n\n\nif __name__ == "__main__":\n main()', 'N, M = list(map(int, input().split()))\n\nans = 0\n\ndef dfs(n, visited):\n global ans\n visited.append(n)\n if len(visited) == N:\n ans += 1\n else:\n for i in l[n-1]:\n if i not in visited:\n dfs(i, visited)\n visited.remove(n)\n\nl = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n l[a-1].append(b)\n l[b-1].append(a) \n\ndfs(1, [])\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s088753415', 's959764831', 's789688345'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 27.0] | [730, 719, 422] |
p03805 | u575431498 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(i):\n if all(visited):\n global ans\n ans += 1\n return\n for j in range(N):\n if g[i][j] and not visited[j]:\n visited[j] = True\n dfs(j)\n visited[j] = False\n\nN, M = map(int, input().split())\ng = [[False] * N for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n g[a-1][b-1] = True\n g[b-1][a-1] = True\n\nans = 0\nvisited = [False] * N\nvisited[0] = True\ndfs(0)', 'def dfs(i):\n if all(visited):\n global ans\n ans += 1\n return\n for j in range(N):\n if g[i][j] and not visited[j]:\n visited[j] = True\n dfs(j)\n visited[j] = False\n return\n\nN, M = map(int, input().split())\ng = [[False] * M for _ in range(M)]\nfor _ in range(M):\n a, b = map(int, input().split())\n g[a-1][b-1] = True\n g[b-1][a-1] = True\n\nans = 0\nvisited = [False] * N\nvisited[0] = True\ndfs(0)', 'from copy import copy\nN, M = map(int, input().split())\nG = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n G[b - 1].append(a - 1)\n G[a - 1].append(b - 1)\n\nans = 0\nst = [[0, [False] * N]]\nwhile len(st) > 0:\n _st = st.pop()\n v = _st[0]\n visited = copy(_st[1])\n if visited[v]:\n continue\n visited[v] = True\n adj_all_visit = True\n for adj in G[v]:\n if visited[adj]:\n continue\n st.append([adj, visited])\n adj_all_visit = False\n if adj_all_visit and all(visited):\n ans += 1\nprint(ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s152319982', 's934617149', 's670626781'] | [3064.0, 3064.0, 3444.0] | [30.0, 30.0, 49.0] | [453, 464, 586] |
p03805 | u576432509 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\na=[]\n\nfor i in range(m):\n ai,bi=map(int,input().split())\n a.append([ai,bi])\n\nni=[0]*n\n \ndef pathm(n,a,bi,pcnt,ni):\n if n==1:\n pcnt=pcnt+1\n print("2:","n:",n,"bi:",bi,"pcnt:",pcnt)\n return pcnt\n else:\n n=n-1\n for mm in range(m):\n if a[mm][0]==bi and ni[a[mm][1]-1]==0:\n# if a[mm][0]==bi :\n ni[a[mm][1]-1]=1\n print("1:","n:",n,"mm:",mm,"a[mm][1]:",a[mm][1],"pcnt:",pcnt)\n pcnt=pathm(n,a,a[mm][1],pcnt,ni)\n if a[mm][1]==bi and ni[a[mm][0]-1]==0 :\n ni[a[mm][0]-1]=1\n# ni[mm]=1\n print("1:","n:",n,"mm:",mm,"a[mm][0]:",a[mm][0],"pcnt:",pcnt)\n pcnt=pathm(n,a,a[mm][0],pcnt,ni)\n return pcnt \n \npcnt=0\npcnt1=pathm(n,a,1,pcnt,ni)\nprint(pcnt1)', 'q=[]\nqq=[]\ndef dfs(j,q,icnt,count,n,qq):\n if len(qq)==n:\n count+=1\n# print("1",n,j,icnt,count,q[j],qq)\n return count\n icnt+=1\n \n for j2 in q[j]:\n if not j2 in qq:\n qq.append(j2)\n# print("2",n,j,icnt,count,q[j],qq)\n count=dfs(j2,q,icnt,count,n,qq)\n qq.pop()\n# print("3",n,j,icnt,count,q[j],qq)\n return count\n\nn,m=map(int,input().split())\nq=[[0]*2 for i in range(m)]\nfor i in range(m):\n q[i]=set(map(int,input().split()))\n\n#n=3\n#m=3\n#ab=[[1,2],[1,3],[2,3]]\n\n#n=7\n#m=7\n#ab=[[1,3],[2,7],[3,4],[4,5],[4,6],[5,6],[6,7]]\n\nq=[[]*2 for i in range(n)]\nfor i in range(m):\n if not q[ab[i][1]-1] in q[ab[i][0]-1]:\n q[ab[i][0]-1].append(ab[i][1]-1) \n if not q[ab[i][0]-1] in q[ab[i][1]-1]:\n q[ab[i][1]-1].append(ab[i][0]-1) \n#print(q) \n\ncount=0\nj=0\nqq=[j]\nicnt=1\ncount=dfs(j,q,icnt,count,n,qq)\nprint(count)\n', 'q=[]\nqq=[]\ndef dfs(j,q,icnt,count,n,qq):\n if len(qq)==n:\n count+=1\n# print("1",n,j,icnt,count,q[j],qq)\n return count\n icnt+=1\n \n for j2 in q[j]:\n if not j2 in qq:\n qq.append(j2)\n# print("2",n,j,icnt,count,q[j],qq)\n count=dfs(j2,q,icnt,count,n,qq)\n qq.pop()\n# print("3",n,j,icnt,count,q[j],qq)\n return count\n\nn,m=map(int,input().split())\nq=[[0]*2 for i in range(m)]\nfor i in range(m):\n q[i]=list(map(int,input().split()))\n\n#n=3\n#m=3\n#ab=[[1,2],[1,3],[2,3]]\n\n#n=7\n#m=7\n#ab=[[1,3],[2,7],[3,4],[4,5],[4,6],[5,6],[6,7]]\n\nq=[[]*2 for i in range(n)]\nfor i in range(m):\n if not q[ab[i][1]-1] in q[ab[i][0]-1]:\n q[ab[i][0]-1].append(ab[i][1]-1) \n if not q[ab[i][0]-1] in q[ab[i][1]-1]:\n q[ab[i][1]-1].append(ab[i][0]-1) \n#print(q) \n\ncount=0\nj=0\nqq=[j]\nicnt=1\ncount=dfs(j,q,icnt,count,n,qq)\nprint(count)\n', 'q=[]\nqq=[]\ndef dfs(j,q,count,n,qq):\n if len(qq)==n:\n count+=1\n return count \n for j2 in q[j]:\n if not j2 in qq:\n qq.append(j2)\n count=dfs(j2,q,count,n,qq)\n qq.pop()\n return count\n\nn,m=map(int,input().split())\nq=[[]*2 for i in range(n)]\nfor i in range(m):\n ai,bi=list(map(int,input().split()))\n if not q[bi-1] in q[ai-1]:\n q[ai-1].append(bi-1) \n q[bi-1].append(ai-1) \n\ncount=0\nj=0\nqq=[j]\ncount=dfs(j,q,count,n,qq)\nprint(count)\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s189244013', 's596676646', 's905087904', 's225365305'] | [3064.0, 3188.0, 3064.0, 3064.0] | [17.0, 18.0, 18.0, 27.0] | [878, 919, 920, 517] |
p03805 | u580904613 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nadj_matrix = [[0] * n for _ in range(N)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n adj_matrix[a-1][b-1] = 1\n adj_matrix[b-1][a-1] = 1\n \ndef dfs(v, used):\n if not False in used:\n return 1\n \n ans = 0\n for i in range(n):\n if not adj_matrix[v][i]:\n continue\n if used[i]:\n continue\n \n used[i] = True\n ans += dfs(i, used)\n used[i] = False\n \n return ans\n\nused = [False] * n\nused[0] = True\n\nprint(dfs(0, used))', 'N, M = map(int, input().split())\nadj_matrix = [[0]* N for _ in range(N)]\n\nfor i in range(M):\n a, b = map(int, input().split())\n adj_matrix[a-1][b-1] = 1\n adj_matrix[b-1][a-1] = 1\n\ndef dfs(v, used):\n if not False in used:\n return 1\n \n ans = 0\n for i in range(N):\n if not adj_matrix[v][i]:\n continue\n if used[i]:\n continue\n \n used[i] = True\n ans += dfs(i, used)\n used[i] = False\n \n return ans\n\nused = [False] * N\nused[0] = True\n\nprint(dfs(0, used))'] | ['Runtime Error', 'Accepted'] | ['s425996575', 's388892569'] | [3064.0, 3064.0] | [17.0, 28.0] | [491, 544] |
p03805 | u583826716 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from copy import deepcopy\n\n\n\ndef wfs(tree, root, node_num):\n lost_list = [root]\n\n def _wfs(tree, root, lost_list) -> int:\n if len(lost_list) == node_num:\n print(lost_list)\n return 1\n counter = 0\n for i in tree[root]:\n if i not in lost_list:\n tmp = deepcopy(lost_list)\n tmp.append(i)\n counter += _wfs(tree, i, tmp)\n return counter\n\n return _wfs(tree, 0, lost_list)\n\n\nn, m = input().rstrip().split()\nn, m = int(n), int(m)\nv = [list() for i in range(n)]\nfor _ in range(m):\n line = [int(i) - 1 for i in input().rstrip().split()]\n v[line[0]].append(line[1])\n v[line[1]].append(line[0])\n\nprint(wfs(v, 0, n))', 'from copy import deepcopy\n\ndef wfs(tree, root, node_num):\n lost_list = [root]\n\n def _wfs(tree, root, lost_list) -> int:\n if len(lost_list) == node_num:\n return 1\n counter = 0\n for i in tree[root]:\n if i not in lost_list:\n tmp = deepcopy(lost_list)\n tmp.append(i)\n counter += _wfs(tree, i, tmp)\n return counter\n\n return _wfs(tree, 0, lost_list)\n\n\nn, m = input().rstrip().split()\nn, m = int(n), int(m)\nv = [list() for i in range(n)]\nfor _ in range(m):\n line = [int(i) - 1 for i in input().rstrip().split()]\n v[line[0]].append(line[1])\n v[line[1]].append(line[0])\n\nprint(wfs(v, 0, n))'] | ['Wrong Answer', 'Accepted'] | ['s948008627', 's696960881'] | [3700.0, 3572.0] | [127.0, 180.0] | [725, 694] |
p03805 | u588081069 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from log import logger\n\nN, M = list(map(int, input().split()))\n\nkey_value = {}\nfor i in range(M):\n a, b = input().split()\n try:\n key_value[a].append(b)\n except KeyError:\n key_value[a] = [b]\n try:\n key_value[b].append(a)\n except KeyError:\n key_value[b] = [a]\n\nlogger.info("key_value: {}\\n".format(key_value))\n\n\n\nnode = "1"\n\nopen_list = [node]\n\nclosed_list = []\n\ncnt = 0\nwhile True:\n \n logger.info(\n "[before] open_list: {}, closed_list: {}".format(open_list, closed_list)\n )\n if len(open_list) == 0:\n break\n else:\n \n node = open_list[0]\n open_list = open_list[1:]\n closed_list.append(node)\n \n if sorted(closed_list) == list(map(str, range(1, N + 1))):\n cnt += 1\n else:\n \n try:\n children = key_value[node]\n for i in range(len(children)):\n if children[i] not in open_list and children[i] not in closed_list:\n open_list.append(children[i])\n except KeyError:\n pass\n logger.info(\n "[after] open_list: {}, closed_list: {}\\n".format(open_list, closed_list)\n )\nprint(cnt)\n', "from log import logger\n\nN, M = map(int, input().split())\nkey_value = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n key_value[a].append(b)\n key_value[b].append(a)\n\nlogger.info('key_value: {}\\n'.format(key_value))\n\nclosed_list = [False] * N\nclosed_list[0] = True\ncnt = 0\n\n\ndef dfs(target):\n global cnt\n logger.info('key_value[target]: {}'.format(key_value[target]))\n if all(closed_list):\n cnt += 1\n return\n for node in key_value[target]:\n logger.info('node: {}'.format(node))\n \n if closed_list[node] is False:\n closed_list[node] = True\n dfs(node)\n closed_list[node] = False\n logger.info('closed_list: {}\\n'.format(closed_list))\n return\n\n\ndfs(0)\nprint(cnt)\n", 'N, M = map(int, input().split())\nopen_list = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n open_list[a].append(b)\n open_list[b].append(a)\n\n\nclosed_list = [False] * N\nclosed_list[0] = True\ncnt = 0\nlevel = 1\n\n\ndef dfs(target):\n global cnt, level\n if all(closed_list):\n cnt += 1\n return\n \n for node in open_list[target]:\n \n if closed_list[node] is False:\n \n closed_list[node] = True\n \n level += 1\n dfs(node)\n level = 1\n \n closed_list[node] = False\n return\n\n\ndfs(0)\nprint(cnt)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s498058004', 's580015649', 's023166072'] | [3064.0, 3064.0, 3064.0] | [18.0, 18.0, 25.0] | [1680, 835, 803] |
p03805 | u593019570 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["n,m = map(int, input().split())\nlink = [[] for i in range(n)]\nfor _ in range(m):\n a,b = map(int, input().split())\n link[a-1].append(b-1)\n link[b-1].append(a-1)\n\nused = [0 for i in range(n)]\nans = 0\nprint(link)\ndef dfs(now, prev):\n global ans\n\n if sum(used) == n:\n #print('+1')\n ans += 1\n\n for i in link[now]:\n #print(now,i,used)\n if i != now and used[i] == 0:\n used[i] = 1\n #print('a')\n dfs(i, now)\n #print('b')\n used[i] = 0\n #print('c')\n\nused[0] = 1\ndfs(0,-1)\nprint(ans)\n\n", 'import itertools\nn,m = map(int,input().split())\n\na = [[] for i in range(n)]\nfor i in range(m):\n b = list(map(int,input().split()))\n a[b[0]-1].append(b[1]-1)\n a[b[1]-1].append(b[0]-1)\n\n#print(a)\n\nc = list(itertools.permutations(range(1, n)))\nlen_c = len(c)\n\n#print(c)\nans = 0\nfor i in range(len_c):\n now = 0\n check = True\n for j in range(n - 1):\n if not c[i][j] in a[now]:\n check = False\n now = c[i][j]\n if check:\n ans += 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s422592365', 's488118908'] | [3064.0, 9388.0] | [30.0, 40.0] | [585, 487] |
p03805 | u603234915 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\ndef dfs(v, visited):\n global adjacency_list, ans\n # copy\n visited_copy = visited[:]\n print("v;%d" % v)\n print(visited)\n \n visited_copy[v] = True\n for a in adjacency_list[v]:\n \n if sum(visited_copy) == N:\n ans += 1\n continue\n \n if visited[a] == True:\n continue\n \n else:\n \n visited_copy[a] = True\n dfs(a, visited_copy) \n \n visited_copy[a] = False\n\nif __name__ == "__main__":\n # input\n N, M = map(int, input().split())\n \n adjacency_list = [[] for _ in range(N)]\n for _ in range(M):\n a, b = map(int, input().split())\n adjacency_list[a-1].append(b-1)\n adjacency_list[b-1].append(a-1)\n\t\n visited = [False] * N\n print(visited)\n ans = 0 \n dfs(0, visited)\n print(ans)', '\ndef dfs_mat(v):\n global adjacency_mat, ans, visited\n \n if sum(visited) == N:\n ans += 1\n return\n for i in range(N):\n if adjacency_mat[v][i]:\n \n if visited[i] == True:\n continue\n \n else:\n \n visited[i] = True\n dfs_mat(i) \n \n visited[i] = False\n\n\nif __name__ == "__main__":\n # input\n N, M = map(int, input().split())\n \n adjacency_mat = [[None]* N for _ in range(N)]\n for _ in range(M):\n a, b = map(int, input().split())\n adjacency_mat[a-1][b-1] = 1\n adjacency_mat[b-1][a-1] = 1\n \n visited = [False] * N\n visited[0] = True \n ans = 0 \n dfs_mat(0)\n print(ans)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s537937038', 's581516964'] | [3828.0, 3064.0] | [83.0, 34.0] | [1130, 1031] |
p03805 | u607563136 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(g,v,depth):\n if seen[v]==True:return 0\n if depth==n:return 1\n seen[v] = True\n paths = 0\n for next_v in g[v]:\n paths += dfs(g,next_v,depth+1)\n seen[v] = False\n return paths\n \nn,m = map(int,input().split())\n\ng = [[]*(n+1) for _ in range(n+1)]\n\nfor _ in range(m):\n a,b = map(int,input().split())\n g[a].append(b)\n g[b].append(a)\n\nseen = [False]*(n+1)\n \ndfs(g,1,1)', 'def dfs(g,v,depth):\n if seen[v]==True:return 0\n if depth==n:return 1\n seen[v] = True\n paths = 0\n for next_v in g[v]:\n paths += dfs(g,next_v,depth+1)\n seen[v] = False\n return paths\n \nn,m = map(int,input().split())\n\ng = [[]*(n+1) for _ in range(n+1)]\n\nfor _ in range(m):\n a,b = map(int,input().split())\n g[a].append(b)\n g[b].append(a)\n\nseen = [False]*(n+1)\n \nprint(dfs(g,1,1))'] | ['Wrong Answer', 'Accepted'] | ['s988534636', 's181850759'] | [9104.0, 9108.0] | [33.0, 36.0] | [414, 421] |
p03805 | u617515020 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nn,m = map(int,input().split())\ne = [tuple(sorted(map(int,input().split()))) for _ in range(m)]\n\nans = 1\nfor i in permutations(range(2, n+1), n-1):\n l = [1] + list(i)\n ans += sum(1 for j in zip(l, l[1:]) if tuple(sorted(j)) in e) == n-1\n\nprint(ans)', 'from itertools import permutations\nn,m = map(int,input().split())\ne = {tuple(sorted(map(int,input().split()))) for _ in range(m)}\n\nans = 1\nfor i in permutations(range(2, n+1), n-1):\n l = [1] + list(i)\n ans += sum(1 for j in zip(l, l[1:]) if tuple(sorted(j)) in e) == n-1\n\nprint(ans)', 'from itertools import permutations\nn,m = map(int,input().split())\ne = [tuple(sorted(map(int,input().split()))) for _ in range(m)]\n\nans = 0\nfor i in permutations(range(2, n+1), n-1):\n l = [1] + list(i)\n ans += sum(1 for j in zip(l, l[1:]) if tuple(sorted(j)) in e) == n-1\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s105957432', 's889909944', 's536582098'] | [3064.0, 3064.0, 3188.0] | [56.0, 44.0, 56.0] | [284, 284, 284] |
p03805 | u626468554 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nn,m = map(int,input().split())\nli = [[0 for _ in range(n)] for _ in range(n)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n a-=1\n b-=1\n li[a][b] = 1\n li[b][a] = 1\n\nnum = [i for i in range(1,n)]\nans = 0\n\nfor v in itertools.permutations(num):\n print(v)\n if li[0][v[0]] == 0:\n continue\n for i in range(len(v)-1):\n if li[v[i]][v[i+1]] == 0:\n break\n elif i==len(v)-2:\n ans += 1\nprint(ans-1)\n\n\n\n\n', 'import itertools\n\nn,m = map(int,input().split())\nli = [[0 for _ in range(n)] for _ in range(n)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n a-=1\n b-=1\n li[a][b] = 1\n li[b][a] = 1\n\nnum = [i for i in range(1,n)]\nans = 0\n\n\nfor v in itertools.permutations(num):\n bre = False\n if li[0][v[0]] == 0:\n continue\n for i in range(len(v)-1):\n if li[v[i]][v[i+1]] == 0:\n bre = True\n break\n if bre:\n continue\n else:\n ans += 1\nprint(ans)\n\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s201907162', 's767154142'] | [3188.0, 3064.0] | [40.0, 27.0] | [482, 516] |
p03805 | u633548583 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nn,m=map(int,input().split())\np=[[False]*n for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1\n b-=1\n p[a][b]=True\n p[b][a]=True\nans=0\nfor i in itertools.permutations(range(1,n),n-1):\n list=[0]+[i]\n if all(p[list[j]][list[j+1]]==True for j in range(n)):\n ans+=1\nprint(ans) ', 'import itertools\nn,m=map(int,input().split())\np=[[False]*n for i in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1\n b-=1\n p[a][b]=True\n p[b][a]=True\nans=0\nfor i in itertools.permutations(range(1,n),n-1):\n list=[0]+[k for k in i]\n if all(p[list[j]][list[j+1]]==True for j in range(n-1)):\n ans+=1\nprint(ans) \n'] | ['Runtime Error', 'Accepted'] | ['s999598357', 's227098646'] | [3064.0, 3064.0] | [18.0, 31.0] | [342, 356] |
p03805 | u634208461 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nN, M = map(int, input().split())\nedge = []\nfor _ in range(M):\n a, b = map(int, input().split())\n edge.append(set((a, b)))\n\np = list(map(lambda x: [1] + list(x), permutations([i for i in range(2, N + 1)])))\n\nans = 0\n\nfor root in p:\n for i in range(len(root) - 1):\n if not set((root[i], root[i + 1])) in edge:\n break\n else:\n print(root)\n ans += 1\n\nprint(ans)\n', 'from itertools import permutations\nN, M = map(int, input().split())\nedge = []\nfor _ in range(M):\n a, b = map(int, input().split())\n edge.append(set((a, b)))\n\np = list(map(lambda x: [1] + list(x), permutations([i for i in range(2, N + 1)])))\n\nans = 0\n\nfor root in p:\n for i in range(len(root) - 1):\n if not set((root[i], root[i + 1])) in edge:\n break\n else:\n ans += 1\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s047073691', 's087258840'] | [3956.0, 3700.0] | [65.0, 53.0] | [436, 416] |
p03805 | u643840641 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['m, n = map(int, input().split())\nedge = [[False for j in range(n)] for i in range(n)]\nfor _ in range(m):\n\ta, b = map(int, input().split())\n\tedge[a-1][b-1] = edge[b-1][a-1] = True\nvisited = [False for _ in range(n)]\nans = 0\ndef dfs(v):\n\tvisited[v] = True\n\tif all(x==True for x in visited):\n\t\tglobal ans\n\t\tans += 1\n\t\treturn\n\tfor i in range(0, n):\n\t\tif edge[v][i]==True and visited[i]==False:\n\t\t\tdfs(i)\n\t\t\tvisited[i] = False\n\t\t\treturn\ndfs(0)\nprint(ans)', 'n, m = map(int, input().split())\nedge = [[False for j in range(n)] for i in range(n)]\nfor _ in range(m):\n\ta, b = map(int, input().split())\n\tedge[a-1][b-1] = edge[b-1][a-1] = True\nvisited = [False for _ in range(n)]\nans = 0\ndef dfs(v):\n\tvisited[v] = True\n\tif all(x==True for x in visited):\n\t\tglobal ans\n\t\tans += 1\n\t\treturn\n\tfor i in range(0, n):\n\t\tif edge[v][i]==True and visited[i]==False:\n\t\t\tdfs(i)\n\t\t\tvisited[i] = False\ndfs(0)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s277342779', 's931298649'] | [3064.0, 3064.0] | [18.0, 40.0] | [449, 439] |
p03805 | u653005308 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\npath=[[[0]*(n+1)]*(n+1)]\nfor i in range(m):\n a,b=map(int,input().split())\n path[a][b]=1\n path[b][a]=1\nvisited=[[0]*(n+1)]\nvisited[1]=1\ndef dfs(position,visited,n):\n all_visited=1\n for i in range(1,n+1):\n if visited[i]==0:\n all_visited=0\n break\n if all_visited==1:\n return 1\n count=0\n for next in range(1,n+1):\n if path[position][next]==0:\n continue\n if visited[next]==1:\n continue\n visited[next]=1\n count+=dfs(next,visited,n)\n visited[i]=0\n visited[position]=0\n\n return count\nprint(1,n,visited)', 'def dfs(v,n,visited):\n all_visited=1\n \n for i in range(n):\n if visited[i]==0:\n all_visited=0\n if all_visited==1:\n return 1\n count=0\n for i in range(n):\n if path[v][i]!=0:\n continue \n if visited[i]==1:\n continue\n visited[i]=1\n count+=dfs(i,n,visited)\n visited[i]=0\n return count\n\nn,m=map(int,input().split())\npath=[[0]*n for i in range(n)]\nfor i in range(n):\n a,b=map(int,input().split())\n path[a-1][b-1]=1\n path[b-1][a-1]=1\nvisited=[0]*n\nvisited[0]=1\nprint(dfs(0,n,visited))\n\n', 'n,m=map(int,input().split())\npath=[[[0]*n]*n]\nfor i in range(m):\n a,b=map(int,input().split())\n path[a][b]=1\n path[b][a]=1\nvisited=[[0]*n]\nvisited[0]=1\ndef dfs(position,visited,n):\n all_visited=1\n for i in range(n):\n if visited[i]==0:\n all_visited=0\n break\n if all_visited==1:\n return 1\n count=0\n for next in range(n):\n if path[position][next]==0:\n continue\n if visited[next]==1:\n continue\n visited[next]=1\n count+=dfs(next,visited,n)\n visited[i]=0\n visited[position]=0\n\n return count\nprint(0,n,visited)', 'n,m=map(int,input().split())\npath=[[0]*n for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n path[a-1][b-1]=1\n path[b-1][a-1]=1\nvisited=[0]*n\nvisited[0]=1\ndef dfs(position,visited,n):\n all_visited=1\n for i in range(n):\n if visited[i]==0:\n all_visited=0\n break\n if all_visited==1:\n return 1\n count=0\n for next in range(n):\n if path[position][next]==0:\n continue\n if visited[next]==1:\n continue\n visited[next]=1\n count+=dfs(next,visited,n)\n \n visited[position]=0\n\n return count\nprint(dfs(0,visited,n))', 'n,m=map(int,input().split())\npath=[[0]*n for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n path[a-1][b-1]=1\n path[b-1][a-1]=1\nvisited=[0]*n\nvisited[0]=1\ndef dfs(position,visited,n):\n all_visited=1\n for i in range(n):\n if visited[i]==0:\n all_visited=0\n break\n if all_visited==1:\n return 1\n count=0\n for next in range(n):\n if path[position][next]==0:\n continue\n if visited[next]==1:\n continue\n visited[next]=1\n count+=dfs(next,visited,n)\n visited[next]=0\n visited[position]=0\n\n return count\nprint(dfs(0,visited,n))\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s055026138', 's139028504', 's474777228', 's898944786', 's979948128'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 20.0, 18.0, 17.0, 37.0] | [1033, 691, 1013, 1039, 1042] |
p03805 | u655834330 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def read_input():\n n, m = map(int, input().split())\n\n edges = []\n nodes = list(range(1, n + 1))\n\n for i in range(m):\n a, b = map(int, input().split())\n edges.append((a, b))\n\n\n edges_dic = {}\n for i in range(n):\n edges_dic[i + 1] = []\n\n for edge in edges:\n edges_dic[edge[0]].append(edge[1])\n edges_dic[edge[1]].append(edge[0])\n\n return n, m, nodes, edges_dic\n\n\n\ndef check_path(curr_node, rest_nodes, edges_dic, through):\n \n if not rest_nodes:\n return 1\n\n \n next_nodes = edges_dic[curr_node]\n targets = []\n for n in next_nodes:\n if n in rest_nodes:\n targets.append(n)\n\n \n if not targets:\n return 0\n\n \n count = 0\n for t in targets:\n new_rest = [r for r in rest_nodes if r != t]\n new_through = through + [curr_node]\n count += check_path(t, new_rest, edges_dic, new_through)\n\n return count\n\n\n\ndef submit():\n n, m, nodes, edges_dic = read_input()\n\n rest_nodes = [r for r in nodes if r != 1]\n print(check_path(1, rest_nodes, edges_dic, []))\n\n', "\n\ndef read_input():\n n, m = map(int, input().split())\n\n edges = []\n nodes = list(range(1, n + 1))\n\n for i in range(m):\n a, b = map(int, input().split())\n edges.append((a, b))\n\n\n edges_dic = {}\n for i in range(n):\n edges_dic[i + 1] = []\n\n for edge in edges:\n edges_dic[edge[0]].append(edge[1])\n edges_dic[edge[1]].append(edge[0])\n\n return n, m, nodes, edges_dic\n\n\n\ndef check_path(curr_node, rest_nodes, edges_dic, through):\n \n if not rest_nodes:\n return 1\n\n \n next_nodes = edges_dic[curr_node]\n targets = []\n for n in next_nodes:\n if n in rest_nodes:\n targets.append(n)\n\n \n if not targets:\n return 0\n\n \n count = 0\n for t in targets:\n new_rest = [r for r in rest_nodes if r != t]\n new_through = through + [curr_node]\n count += check_path(t, new_rest, edges_dic, new_through)\n\n return count\n\n\ndef submit():\n n, m, nodes, edges_dic = read_input()\n\n rest_nodes = [r for r in nodes if r != 1]\n paths = check_path(1, rest_nodes, edges_dic, [])\n print(paths)\n\n\nif __name__ == '__main__':\n submit()\n"] | ['Wrong Answer', 'Accepted'] | ['s174428824', 's227425115'] | [3064.0, 3064.0] | [19.0, 33.0] | [1408, 1471] |
p03805 | u658987783 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nn,m=map(int,input().split())\ns=[set(map(int,input().split())) for _ in range(n)]\n\nans=0\nx=[i for i in range(2,n+1)]\nprint(x)\ncand=itertools.permutations(x)\nprint(cand)\nfor i in cand:\n crnt=1\n for nxt in i:\n if set([crnt,nxt]) in s:\n crnt=nxt\n else:\n break\n else:\n ans+=1\nprint(ans)', 'from itertools import permutations\nn,m=map(int,input().split())\ns=[set(map(int,input().split())) for _ in range(m)]\n\nans=0\nx=[i for i in range(2,n+1)]\ncand=permutations(x)\nfor i in cand:\n crnt=1\n for nxt in i:\n if set([crnt,nxt]) in s:\n crnt=nxt\n else:\n break\n else:\n ans+=1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s970519990', 's642570412'] | [3064.0, 3064.0] | [24.0, 49.0] | [320, 307] |
p03805 | u659100741 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["cnt = 0\n\ndef dfs(v, n, used, linked_list):\n global cnt\n if len(used) == n:\n cnt += 1\n return\n else:\n for next_v in linked_list[v]:\n if next_v not in used:\n used.append(next_v)\n dfs(next_v, n, used, linked_list)\n #used.remove(next_v)\n return\n\ndef main():\n global cnt\n n, m = map(int, input().split())\n linked_list = [[] for _ in range(n+1)]\n for i in range(m):\n a, b = map(int, input().split())\n linked_list[a].append(b)\n linked_list[b].append(a)\n used = [1]\n dfs(1, n, used, linked_list)\n print(cnt)\n\nif __name__ == '__main__':\n main()\n \n", "cnt = 0\n\ndef dfs(v, n, used, linked_list):\n global cnt\n if len(used) == n:\n cnt += 1\n return\n else:\n for next_v in linked_list[v]:\n if next_v not in used:\n used.append(next_v)\n dfs(next_v, n, used, linked_list)\n used.remove(next_v)\n return\n\ndef main():\n global cnt\n n, m = map(int, input().split())\n linked_list = [[] for _ in range(n+1)]\n for i in range(m):\n a, b = map(int, input().split())\n linked_list[a].append(b)\n linked_list[b].append(a)\n used = [1]\n dfs(1, n, used, linked_list)\n print(cnt)\n\nif __name__ == '__main__':\n main()\n \n"] | ['Wrong Answer', 'Accepted'] | ['s808037694', 's707288227'] | [3064.0, 3064.0] | [17.0, 28.0] | [679, 678] |
p03805 | u677393869 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\nN, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([False] * N)\n\n\nfor m in range(M):\n line = map(int, input().split())\n paths = [x - 1 for x in line]\n path_matrix[paths[0]][paths[1]] = True\n path_matrix[paths[1]][paths[0]] = True\n\n\nvisited = [False] * N\n\n\n\ndef dfs(now, depth):\n if visited[now]:\n return 0\n if depth == N - 1:\n return 1\n\n visited[now] = True\n total_paths = 0\n for i in range(0, N):\n if path_matrix[now][i]:\n total_paths += dfs(i, depth + 1)\n\n\n return total_paths\n\nprint(dfs(0, 0))', '\nN, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([False] * N)\n\n\nfor m in range(M):\n line = map(int, input().split())\n paths = [x - 1 for x in line]\n path_matrix[paths[0]][paths[1]] = True\n path_matrix[paths[1]][paths[0]] = True\n\n\nvisited = [False] * N\n\n\n\ndef dfs(now, depth):\n if visited[now]:\n return 0\n if depth == N - 1:\n return 1\n\n visited[now] = True\n total_paths = 0\n for i in range(0, N):\n if path_matrix[now][i]:\n total_paths += dfs(i, depth + 1)\n\n return total_paths\n\nprint(dfs(0, 0))', '\nN, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([False] * N)\n\n\nfor m in range(M):\n line = map(int, input().split())\n paths = [x - 1 for x in line]\n path_matrix[paths[0]][paths[1]] = True\n path_matrix[paths[1]][paths[0]] = True\n\n\nvisited = [False] * N\n\n\n\ndef dfs(now, depth):\n if visited[now]:\n return 0\n if depth == N - 1:\n return 1\n\n visited[now] = True\n total_paths = 0\n for i in range(0, N):\n if path_matrix[now][i]:\n total_paths += dfs(i, depth + 1)\n\n visited[now] = False\n\n return total_paths\n\nprint(dfs(0, 0))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s200852142', 's832736125', 's071378183'] | [9224.0, 9232.0, 9152.0] | [28.0, 29.0, 32.0] | [874, 873, 899] |
p03805 | u679390859 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input(),aplit())\n\npath = [[] for i in range(N)]\n\nfor _ in range(M):\n\ta,b = map(int,input(),split())\n\tpath[a-1],append(b-1)\n path[b-1],append(a-1)\nvis = [0 for i in range(N)]\ncnt = 0\n\ndef dfs(now,path):\n\tglobal cnt\n \tif depth == N: cnt+=1\n\tfor new in path[now]:\n \tif vis[new] == 0:\n\t\t\tvis[new] = 1\n \tdfs(new,depth+1)\n \tvis[new] = 0\n\nvis[0] = 1\ndfs(0,1)\nprint(cnt)', 'N,M = map(int,input().split())\n\npath = [[] for i in range(N)]\n\nfor _ in range(M):\n\ta,b = map(int,input().split())\n\tpath[a-1].append(b-1)\n\tpath[b-1].append(a-1)\nvis = [0 for i in range(N)]\ncnt = 0\n\ndef dfs(now,depth):\n\tglobal cnt\n\tif depth == N: cnt+=1\n\tfor new in path[now]:\n\t\tif vis[new] == 0:\n\t\t\tvis[new] = 1\n\t\t\tdfs(new,depth+1)\n\t\t\tvis[new] = 0\n\nvis[0] = 1\ndfs(0,1)\nprint(cnt)\n'] | ['Runtime Error', 'Accepted'] | ['s614124162', 's241557309'] | [8960.0, 9012.0] | [23.0, 35.0] | [399, 379] |
p03805 | u686036872 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = map(int, input().split())\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nvisited = [0]*N\nans = 0\nvisited[0] = 1\n\ndef dfs(v):\n global ans\n if 0 not in visited:\n return 1\n\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0))', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nfor i in itertools.permutations(range(N)):\n if i[0]==0:\n for j in range(N-1):\n result=1\n result*=matrix[i[j]][i[j+1]]\n if result==1:\n count+=1\n else:\n break\nprint(count)', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nresult=1\nfor i in itertools.permulations(range(1, N+1)):\n if i==1:\n for j in range():\n result+=matrix[i[j]][i[j+1]]\n if result=1:\n count+=1\n else:\n result=1\nprint(count)', 'N, M = map(int, input().split())\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nvisited = [0]*N\nans = 0\nvisited[0] = 1\n\ndef dfs(v):\n if 0 not in visited:\n return 1\n\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0))', 'N, M = map(int, input().split())\n\nG = [[]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1] = b-1\n G[b-1] = a-1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nfor i in itertools.permutations(range(N)):\n if i[0]==0:\n result=1\n for j in range(N-1):\n result*=matrix[i[j]][i[j+1]]\n if result==1:\n count+=1\n else:\n break\nprint(count)', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nresult=1\nfor i in itertools.permulations(range(N)):\n if i==0:\n for j in range(N-1):\n result*=matrix[i[j]][i[j+1]]\n if result=1:\n count+=1\n else:\n result=1\n else:\n break\nprint(count)', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nfor i in itertools.permulations(range(N)):\n if i[0]==0:\n for j in range(N-1):\n result=1\n result*=matrix[i[j]][i[j+1]]\n if result==1:\n count+=1\n else:\n break\nprint(count)\n ', 'N, M = map(int, input().split())\n\nG = [[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1] = b-1\n G[b-1] = a-1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nresult=1\nfor i in itertools.permulations(range(1, N+1)):\n if i==1:\n for j in range(N-1):\n result+=matrix[i[j]][i[j+1]]\n if result=1:\n count+=1\n else:\n result=1\n else:\n break\nprint(count)', 'N, M = map(int, input().split())\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1][b - 1] = 1\n G[b-1][a - 1] = 1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[x]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\n\nG = [[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1][b - 1] = 1\n G[b-1][a - 1] = 1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[x]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\nmatrix=[[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n matrix[a-1][b-1]=1\n matrix[b-1][a-1]=1\nimport itertools \ncount=0\nfor i in itertools.permulations(range(N)):\n if i[0]==0:\n for j in range(N-1):\n result=1\n result*=matrix[i[j]][i[j+1]]\n if result=1:\n count+=1\n else:\n break\nprint(count)', 'N, M = map(int, input().split())\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1] = b-1\n G[b-1] = a-1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\n\nG = [[0]*N for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1][b - 1] = 1\n G[b-1][a - 1] = 1\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))', 'N, M = map(int, input().split())\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nvisited = [0]*N\nvisited[0] = 1\n\ndef dfs(v, visited):\n if 0 not in visited:\n return 1\n\n ans = 0\n for i in G[v]:\n if visited[i] == 0:\n visited[i] = 1\n ans += dfs(i, visited)\n visited[i] = 0\n\n return ans\n\nprint(dfs(0, visited))'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s044797375', 's053828886', 's105446178', 's136348096', 's344550966', 's372578830', 's593870205', 's614458282', 's625768011', 's678594627', 's712040623', 's882696199', 's966033419', 's969271336', 's987326694', 's184342375'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3192.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [28.0, 34.0, 17.0, 17.0, 17.0, 32.0, 17.0, 17.0, 18.0, 17.0, 17.0, 18.0, 17.0, 17.0, 17.0, 24.0] | [431, 431, 436, 425, 437, 427, 458, 436, 438, 463, 445, 448, 430, 435, 448, 447] |
p03805 | u686390526 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int, input().split())\nm=[]\nfor i in range(M):\n m.append(list(map(int, input().split())))\n\n\nimport copy\ndef check(c):\n if len(c) != N-1:\n return False\n\n for k in range(2**len(c)):\n f=False\n cc=copy.deepcopy(c)\n for l in range(len(c)):\n if k>>l&1==1:\n tmp=cc[l][0]\n cc[l][0]=cc[l][1]\n cc[l][1]=tmp\n \n\n start_table = [0]*N\n end_table = [0]*N\n start = -1\n # end = -1\n # print(c)\n\n for l in cc:\n start_table[l[0]-1] += 1\n if start_table[l[0]-1] == 2:\n f=True\n break\n if f:\n continue\n \n \n for l in cc:\n end_table[l[1]-1] += 1\n if end_table[l[1]-1] == 2:\n f=True\n break\n if f:\n continue\n \n for i in range(len(cc)):\n if cc[i][0] == 1:\n start = i\n # if c[i][1]==N:\n # end = i\n\n\n if start==-1:\n continue\n\n # if end == -1:\n # return False\n \n # print(cc)\n return True\n\n\nn=0\nfor i in range(2**M):\n c=[]\n for j in range(M):\n if i >> j & 1==1:\n c.append(m[j])\n if check(c):\n n += 1\n\n\n\nprint(n)\n\n', 'import itertools\n\nn, m = map(int, input().split())\ngraph = {i + 1 : set() for i in range(n)}\nfor i in range(m):\n a, b = map(int, input().split())\n graph[a] |= set([b])\n graph[b] |= set([a])\ncount = 0\nnode = [i + 2 for i in range(n - 1)]\nfor i in itertools.permutations(node):\n route = [1] + list(i)\n flag = True\n for j in range(n - 1):\n if route[j + 1] not in graph[route[j]]:\n flag = False\n break\n if flag == True:\n count += 1\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s582882903', 's331793834'] | [3444.0, 3064.0] | [2104.0, 29.0] | [1102, 497] |
p03805 | u693391925 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\nimport queue\nimport copy\nimport sys\nfrom astropy.io.fits.convenience import append\nsys.setrecursionlimit(50000000) \ninput=sys.stdin.readline\n\n\nN, M = map(int, input().split())\nl = []\n\nfor i in range(M):\n l.append(list(map(lambda x: int(x)-1 , input().split())))\n\nlis = [[] for i in range(N)]\n\nfor i in range(M):\n lis[l[i][0]].append(l[i][1])\n lis[l[i][1]].append(l[i][0])\n\n\ndef dfs():\n re=0\n q1 =[[0]*N]\n q2=[0]\n while len(q1) != 0:\n \n visited=q1.pop()\n v=q2.pop()\n visited[v]=1\n if all(visited[c]==1 for c in range(N)):\n re += 1\n elif len(lis[v]) != 0:\n for i in lis[v]:\n if visited[i] == 0:\n hoge=copy.deepcopy(visited) \n q1.append(hoge)\n q2.append(i)\n return re\n\nprint(dfs())\n', '\nimport copy\nimport sys\nsys.setrecursionlimit(50000000) \n\n\nN, M = map(int, input().split())\nl = []\n\nfor i in range(M):\n l.append(list(map(lambda x: int(x)-1 , input().split())))\n\nlis = [[] for i in range(N)]\n\nfor i in range(M):\n lis[l[i][0]].append(l[i][1])\n lis[l[i][1]].append(l[i][0])\n\ndef dfs():\n re=0\n q1 =[[0]*N]\n q2=[0]\n while len(q1) != 0:\n \n visited=q1.pop()\n v=q2.pop()\n visited[v]=1\n if all(visited[c]==1 for c in range(N)):\n re += 1\n elif len(lis[v]) != 0:\n for i in lis[v]:\n if visited[i] == 0:\n hoge=copy.deepcopy(visited) \n q1.append(hoge)\n q2.append(i)\n return re\n\nprint(dfs())\n'] | ['Runtime Error', 'Accepted'] | ['s495246799', 's902106979'] | [4080.0, 3444.0] | [27.0, 165.0] | [907, 821] |
p03805 | u694810977 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nq = []\nfor i in range(m):\n a, b = map(int, input().split())\n q.append({a, b})\ncnt = 0\nwhile cnt != 10000:\n a = q.pop()\n for j in q:\n if len(j & a) != 0: \n j |= a\n count = 0\n break\n else: \n q = [a] + q\n if count > len(q):\n break\n count += 1\n for i in q:\n tmp = list(i)\n if tmp == array:\n cnt += 1\nprint(cnt)\n', 'N, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([False] * N)\n\n\nfor m in range(M):\n a,b = map(int, input().split())\n path_matrix[a-1][b-1] = True\n path_matrix[b-1][a-1] = True\n\n\nvisited = [False] * N \n\ndef dfs(now,depth):\n if visited[now]:\n return 0\n if depth == N-1:\n return 1\n \n visited[now] = True\n total_path = 0\n for i in range(n):\n if path_matrix[now][i]:\n total_path += dfs(i,depth+1) \n\n visited[now] = False\n\n return total_path\n\nprint(dfs(0,0))', 'N, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([False] * N)\n\n\nfor m in range(M):\n a,b = map(int, input().split())\n path_matrix[a-1][b-1] = True\n path_matrix[b-1][a-1] = True\n\n\nvisited = [False] * N \ndef dfs(now,depth):\n if visited[now]:\n return 0\n if depth == N-1:\n return 1\n \n visited[now] = True\n total_path = 0\n for i in range(N):\n if path_matrix[now][i]:\n total_path += dfs(i,depth+1)\n\n visited[now] = False\n\n return total_path\n\n\nprint(dfs(0,0))'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s923578659', 's962886127', 's446646001'] | [3064.0, 3064.0, 3064.0] | [17.0, 21.0, 34.0] | [530, 1200, 1407] |
p03805 | u724687935 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def main():\n import sys\n from itertools import permutations\n \n readlines = sys.stdin.buffer.readlines\n N, M = map(int, input().split())\n edge = [[0] * N for _ in range(N)]\n for s in readlines():\n a, b = map(int, s.split())\n a -= 1; b -= 1\n edge[a][b] = 1\n edge[b][a] = 1\n\n cnt = 0\n for path in permutations(range(1, N)):\n path = [0] + list(path)\n for i in range(N - 1):\n v = path[i]\n nv = path[i + 1]\n if edge[v][nv] == 0:\n break\n else:\n cnt += 1\n print(cnt)\n\n\nif __name__ == "__main__":\n main()\n', 'N, M = map(int, input().split())\n\nedges = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n edges[a - 1].append(b - 1)\n edges[b - 1].append(a - 1)\n\n\ndef dfs(node, track):\n if track == [False] * N:\n global res\n res += 1\n else:\n for dst in edges[node]:\n if track[dst]:\n track[dst] = False\n dfs(dst, track)\n\n\nres = 0\ninit_track = [True] + [False] * N\ndfs(0, init_track)\n\nprint(res)\n', 'def main():\n import sys\n from itertools import permutations\n \n readlines = sys.stdin.readlines\n N, M = map(int, input().split())\n edge = [[0] * N for _ in range(N)]\n for s in readlines():\n a, b = map(int, s.split())\n a -= 1; b -= 1\n edge[a][b] = 1\n edge[b][a] = 1\n\n cnt = 0\n for path in permutations(range(1, N)):\n path = [0] + list(path)\n for i in range(N - 1):\n v = path[i]\n nv = path[i + 1]\n if edge[v][nv] == 0:\n break\n else:\n cnt += 1\n print(cnt)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s506602877', 's562880179', 's699476409'] | [3064.0, 3064.0, 3064.0] | [22.0, 17.0, 25.0] | [675, 483, 668] |
p03805 | u729119068 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nN,M=map(int,input().split())\nedges={tuplec(sorted(map(int,input().split()))) for i in range(M)}\nans=0\nfor i in itertools.permutations(range(2,N+1),N-1):\n l=[1]+list(i)\n ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1\nprint(ans)', 'import itertools\nN,M=map(int,input().split())\nedges={tuplec(sorted(map(int,input().split()))) for i in range(M)}\nans=0\nfor i in itertools.permutations(range(2,N+1)):\n l=[1]+list(i)\n ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1\nprint(ans)', 'import itertools\nN,M=map(int,input().split())\nedges={tuple(sorted(map(int,input().split()))) for i in range(M)}\nans=0\nfor i in itertools.permutations(range(2,N+1)):\n l=[1]+list(i)\n ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s267953821', 's633933338', 's574521608'] | [8952.0, 8920.0, 9120.0] | [27.0, 26.0, 47.0] | [276, 272, 271] |
p03805 | u732870425 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\n\nN, M = map(int, input().split())\nedge = [[0] * (N+1) for _ in range(N+1)]\nfor i in range(M):\n a, b = map(int, input().split())\n edge[a][b] = 1\n edge[b][a] = 1\n\nans = 0\nnode = list(range(1, N+1))\nfor x in itertools.permutations(node):\n for i in range(N-1):\n if not edge[x[i]][x[i+1]]:\n break\n else:\n ans += 1\n\nprint(ans // 2)', 'import itertools\n\n\nN, M = map(int, input().split())\nedge = [[0] * (N+1) for _ in range(N+1)]\nfor i in range(M):\n a, b = map(int, input().split())\n edge[a][b] = 1\n edge[b][a] = 1\n\nans = 0\nnode = list(range(1, N+1))\nfor x in itertools.permutations(node):\n if x[0] == 1:\n for i in range(N-1):\n if not edge[x[i]][x[i+1]]:\n break\n else:\n ans += 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s239725702', 's788880782'] | [3064.0, 3064.0] | [90.0, 30.0] | [417, 416] |
p03805 | u739959951 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nn,m=(map(int,input().split()))\nl=[]\n\nfor _ in range(m):\n a,b=(map(int,input().split()))\n l.append([a,b])\n\nans=0\nans_list=[0]*n\n\nfor i in range(n):\n l_new=l[0:i]+l[i+1:n]\n l_new=itertools.chain.from_iterable(l_new)\n for i in l_new:\n ans_list[int(i)-1]+=1\n print(ans_list)\n if (ans_list[0]==1) and (ans_list.count(2)==(n-2)) and (ans_list.count(1)==2):\n ans+=1\n ans_list=[0]*n\n \nprint(ans)', 'N, M = map(int, input().split()) \ng = [[] for _ in range(N)] \nfor _ in range(M):\n a, b = map(int, input().split())\n g[a-1].append(b-1)\n g[b-1].append(a-1)\nprint(g)\n\n\nis_checked = [False] * N\n\ndef dfs(i):\n cnt = 0\n is_checked[i] = True\n if not(False in is_checked):\n return 1\n else:\n for j in g[i]:\n if not(is_checked[j]):\n cnt += dfs(j)\n is_checked[j] = False\n return cnt\n \nans = dfs(0)\nprint(ans)', 'N, M = map(int, input().split()) \ng = [[] for _ in range(N)] \nfor _ in range(M):\n a, b = map(int, input().split())\n g[a-1].append(b-1)\n g[b-1].append(a-1)\n\n\nis_checked = [False] * N\n\ndef dfs(i):\n cnt = 0\n is_checked[i] = True\n if not(False in is_checked):\n return 1\n else:\n for j in g[i]:\n if not(is_checked[j]):\n cnt += dfs(j)\n is_checked[j] = False\n return cnt\n \nans = dfs(0)\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s476708656', 's702459728', 's530195910'] | [3064.0, 3064.0, 3064.0] | [18.0, 24.0, 25.0] | [420, 568, 559] |
p03805 | u747703115 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nfrom math import factorial as fa\nP = itertools.permutations(list(range(n)))\nn, m = map(int, input().split())\nG = [set() for _ in range(n)]\nfor _ in range(m):\n a,b = map(lambda x:int(x)-1, input().split())\n G[a].add(b)\n G[b].add(a)\n\nans = 0\nfor _ in range(fa(n)):\n p = next(P)\n if p[0] != 0:\n break\n f = True\n for pnw,pnx in zip(p,p[1:]):\n if not pnx in G[pnw]:\n f = False\n break\n if f:\n ans += 1\nprint(ans)', 'import itertools\nn, m = map(int, input().split())\nG = [set() for _ in range(n)]\nfor _ in range(m):\n a,b = map(lambda x:int(x)-1, input().split())\n G[a].add(b)\n G[b].add(a)\n\nP = [*itertools.permutations(range(1,n))]\nans = 0\nfor p in P:\n nw = 0\n for nx in p:\n if nx in G[nw]:\n nw = nx\n else:\n break\n else:\n ans += 1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s774541324', 's260128708'] | [8920.0, 9360.0] | [25.0, 33.0] | [490, 385] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.