{"id":372215,"date":"2024-05-21T05:07:01","date_gmt":"2024-05-21T05:07:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=372215"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T05:07:01","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=372215","title":{"rendered":"<span>\u041f\u043e\u0438\u0441\u043a \u0446\u0438\u043a\u043b\u0430 \u042d\u0439\u043b\u0435\u0440\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c backtracking<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><em>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044c \u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u043c, \u043d\u043e \u0437\u0430\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c. \u0421\u0432\u044f\u0437\u0430\u043d \u043e\u043d \u0441 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0432\u0435\u0440\u0448\u0438\u043d \u0433\u0440\u0430\u0444\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0431\u0440\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0440\u0448\u0438\u043d? \u0412\u043e\u0442 \u044d\u0442\u0430 \u0438\u0434\u0435\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f.<\/em>  <\/p>\n<p>\u041a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0446\u0438\u043a\u043b \u042d\u0439\u043b\u0435\u0440\u0430 \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0435\u0433\u043e \u043c\u0430\u0440\u0448\u0440\u0443\u0442 (\u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440). \u041f\u043e \u0441\u0443\u0442\u0438, \u0437\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d. \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 dict_to_setEdge. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f dfs, \u0442\u043e \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/429\/030\/1b8\/4290301b829d581a8ff91f6efefef94b.jpg\" alt=\"\u0440\u0438\u0441. \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\" title=\"\u0440\u0438\u0441. \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\" width=\"525\" height=\"90\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/429\/030\/1b8\/4290301b829d581a8ff91f6efefef94b.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0440\u0438\u0441. \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"python\"># \u043d\u0435 \u042d\u0439\u043b\u0435\u0440 G1 = {     1: [2, 3, 5],     2: [1, 4, 5],     3: [1, 4, 5],     4: [2, 3, 5],     5: [1, 2, 3, 4] }  # \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 G2 = {     1: [2, 3, 5],     2: [1, 4, 5, 6],     3: [1, 4, 5],     4: [2, 3, 5, 6],     5: [1, 2, 3, 4],     6: [2, 4] }  # \u042d\u0439\u043b\u0435\u0440 G3 = {     1: [2, 3, 5, 7],     2: [1, 4, 5, 6],     3: [1, 4, 5, 7],     4: [2, 3, 5, 6],     5: [1, 2, 3, 4],     6: [2, 4],     7: [1, 3] }  def dfs(g, v, path):     #print(\"path =\", path)     if len(path)-1 == len(edgeSet):          return path     for w in g[v]:         if not {v, w} in path:              path.append({v, w})             newpath = dfs(g, w, path)              if newpath:                  return newpath      path.pop()     def dict_to_setEdge(G):     s = []     for v in G:         for z in G[v]:             if not {v, z} in s:                 s.append({v, z})     return s      v = [1, 2]  for i,g in enumerate([G1, G2, G3]):     edgeSet = dict_to_setEdge(g)     print(\"==== \u0433\u0440\u0430\u0444 ===\", i+1)     for s in v:         print(\" \u0434\u043b\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b =\", s)         p = dfs(g, s, [{s, None}])         if not p:             print(\"\u042d\u0439\u043b\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\")         elif len({s, None}.intersection(p[-1])):             print(\"\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         else: print(\"\u041f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         print()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/d5b\/a23\/6e0\/d5ba236e08fc96c5cf17341e2f085558.jpg\" width=\"1031\" height=\"428\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d5b\/a23\/6e0\/d5ba236e08fc96c5cf17341e2f085558.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u0443\u043b\u044c\u0442\u0438-\u0433\u0440\u0430\u0444\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0431\u0440\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a \u0434\u0432\u0443\u043c \u0441\u043c\u0435\u0436\u043d\u044b\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c (3,7) \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u0440\u0435\u0431\u0440\u043e (\u0434\u043b\u044f G5) \u0438\u043b\u0438 \u0435\u0449\u0435 \u0434\u0432\u0430 \u0440\u0435\u0431\u0440\u0430 (\u0434\u043b\u044f G4). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, G4 \u042d\u0439\u043b\u0435\u0440\u043e\u0432\u044b\u043c \u0433\u0440\u0430\u0444\u043e\u043c \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"python\"># \u042d\u0439\u043b\u0435\u0440 G4 = {     1: [(2,1), (3,1), (5,1), (7,1)],     2: [(1,1), (4,1), (5,1), (6,1)],     3: [(1,1), (4,1), (5,1), (7,1), (7,2), (7,3)],     4: [(2,1), (3,1), (5,1), (6,1)],     5: [(1,1), (2,1), (3,1), (4,1)],     6: [(2,1), (4,1)],     7: [(1,1), (3,1), (3,2), (3,3)] }  # \u043d\u0435 \u042d\u0439\u043b\u0435\u0440 G5 = {     1: [(2,1), (3,1), (5,1), (7,1)],     2: [(1,1), (4,1), (5,1), (6,1)],     3: [(1,1), (4,1), (5,1), (7,1), (7,2)],     4: [(2,1), (3,1), (5,1), (6,1)],     5: [(1,1), (2,1), (3,1), (4,1)],     6: [(2,1), (4,1)],     7: [(1,1), (3,1), (3,2)] }  def dfs(g, v, path):     #print(\"path =\", path)     if len(path)-1 == len(edgeSet):         return path          for w in g[v]:         if not ({v, w[0]}, w[1]) in path:              path.append(({v, w[0]}, w[1]))             newpath = dfs(g, w[0], path)              if newpath:                  return newpath      path.pop()     def dict_to_setEdge(G):     s = []     for v in G:         for z in G[v]:             if not ({v, z[0]}, z[1]) in s:                 s.append(({v, z[0]}, z[1]))     return s       v = [1, 2]  for i,g in enumerate([G4, G5]):     edgeSet = dict_to_setEdge(g)     #print(edgeSet); input()     print(\"\\n==== \u0433\u0440\u0430\u0444 ===\", i+1)     for s in v:         print(\"\u0434\u043b\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b =\", s)         p = dfs(g, s, [{s, None}])         if not p:             print(\"\u042d\u0439\u043b\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\")         elif len({s, None}.intersection(p[-1][0])):             print(\"\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         else: print(\"\u041f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         print()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/636\/193\/0a5\/6361930a54e3ca1ff79bd62d82054899.jpg\" width=\"952\" height=\"340\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/636\/193\/0a5\/6361930a54e3ca1ff79bd62d82054899.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/803963\/\"> https:\/\/habr.com\/ru\/articles\/803963\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><em>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044c \u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u043c, \u043d\u043e \u0437\u0430\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c. \u0421\u0432\u044f\u0437\u0430\u043d \u043e\u043d \u0441 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0432\u0435\u0440\u0448\u0438\u043d \u0433\u0440\u0430\u0444\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0431\u0440\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0440\u0448\u0438\u043d? \u0412\u043e\u0442 \u044d\u0442\u0430 \u0438\u0434\u0435\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f.<\/em>  <\/p>\n<p>\u041a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0446\u0438\u043a\u043b \u042d\u0439\u043b\u0435\u0440\u0430 \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0435\u0433\u043e \u043c\u0430\u0440\u0448\u0440\u0443\u0442 (\u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440). \u041f\u043e \u0441\u0443\u0442\u0438, \u0437\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d. \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 dict_to_setEdge. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f dfs, \u0442\u043e \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u043c. <\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0440\u0438\u0441. \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"python\"># \u043d\u0435 \u042d\u0439\u043b\u0435\u0440 G1 = {     1: [2, 3, 5],     2: [1, 4, 5],     3: [1, 4, 5],     4: [2, 3, 5],     5: [1, 2, 3, 4] }  # \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 G2 = {     1: [2, 3, 5],     2: [1, 4, 5, 6],     3: [1, 4, 5],     4: [2, 3, 5, 6],     5: [1, 2, 3, 4],     6: [2, 4] }  # \u042d\u0439\u043b\u0435\u0440 G3 = {     1: [2, 3, 5, 7],     2: [1, 4, 5, 6],     3: [1, 4, 5, 7],     4: [2, 3, 5, 6],     5: [1, 2, 3, 4],     6: [2, 4],     7: [1, 3] }  def dfs(g, v, path):     #print(\"path =\", path)     if len(path)-1 == len(edgeSet):          return path     for w in g[v]:         if not {v, w} in path:              path.append({v, w})             newpath = dfs(g, w, path)              if newpath:                  return newpath      path.pop()     def dict_to_setEdge(G):     s = []     for v in G:         for z in G[v]:             if not {v, z} in s:                 s.append({v, z})     return s      v = [1, 2]  for i,g in enumerate([G1, G2, G3]):     edgeSet = dict_to_setEdge(g)     print(\"==== \u0433\u0440\u0430\u0444 ===\", i+1)     for s in v:         print(\" \u0434\u043b\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b =\", s)         p = dfs(g, s, [{s, None}])         if not p:             print(\"\u042d\u0439\u043b\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\")         elif len({s, None}.intersection(p[-1])):             print(\"\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         else: print(\"\u041f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         print()<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u0443\u043b\u044c\u0442\u0438-\u0433\u0440\u0430\u0444\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0431\u0440\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a \u0434\u0432\u0443\u043c \u0441\u043c\u0435\u0436\u043d\u044b\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c (3,7) \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u0440\u0435\u0431\u0440\u043e (\u0434\u043b\u044f G5) \u0438\u043b\u0438 \u0435\u0449\u0435 \u0434\u0432\u0430 \u0440\u0435\u0431\u0440\u0430 (\u0434\u043b\u044f G4). \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, G4 \u042d\u0439\u043b\u0435\u0440\u043e\u0432\u044b\u043c \u0433\u0440\u0430\u0444\u043e\u043c \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"python\"># \u042d\u0439\u043b\u0435\u0440 G4 = {     1: [(2,1), (3,1), (5,1), (7,1)],     2: [(1,1), (4,1), (5,1), (6,1)],     3: [(1,1), (4,1), (5,1), (7,1), (7,2), (7,3)],     4: [(2,1), (3,1), (5,1), (6,1)],     5: [(1,1), (2,1), (3,1), (4,1)],     6: [(2,1), (4,1)],     7: [(1,1), (3,1), (3,2), (3,3)] }  # \u043d\u0435 \u042d\u0439\u043b\u0435\u0440 G5 = {     1: [(2,1), (3,1), (5,1), (7,1)],     2: [(1,1), (4,1), (5,1), (6,1)],     3: [(1,1), (4,1), (5,1), (7,1), (7,2)],     4: [(2,1), (3,1), (5,1), (6,1)],     5: [(1,1), (2,1), (3,1), (4,1)],     6: [(2,1), (4,1)],     7: [(1,1), (3,1), (3,2)] }  def dfs(g, v, path):     #print(\"path =\", path)     if len(path)-1 == len(edgeSet):         return path          for w in g[v]:         if not ({v, w[0]}, w[1]) in path:              path.append(({v, w[0]}, w[1]))             newpath = dfs(g, w[0], path)              if newpath:                  return newpath      path.pop()     def dict_to_setEdge(G):     s = []     for v in G:         for z in G[v]:             if not ({v, z[0]}, z[1]) in s:                 s.append(({v, z[0]}, z[1]))     return s       v = [1, 2]  for i,g in enumerate([G4, G5]):     edgeSet = dict_to_setEdge(g)     #print(edgeSet); input()     print(\"\\n==== \u0433\u0440\u0430\u0444 ===\", i+1)     for s in v:         print(\"\u0434\u043b\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b =\", s)         p = dfs(g, s, [{s, None}])         if not p:             print(\"\u042d\u0439\u043b\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\")         elif len({s, None}.intersection(p[-1][0])):             print(\"\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         else: print(\"\u041f\u043e\u043b\u0443-\u042d\u0439\u043b\u0435\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\", p[1:])         print()<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/803963\/\"> https:\/\/habr.com\/ru\/articles\/803963\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-372215","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372215"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372215\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}