{"id":15116,"date":"2024-01-08T20:36:23","date_gmt":"2024-01-08T17:06:23","guid":{"rendered":"https:\/\/rasanegar.com\/blog\/%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6\/"},"modified":"2024-01-08T20:36:23","modified_gmt":"2024-01-08T17:06:23","slug":"%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6","status":"publish","type":"post","link":"https:\/\/rasanegaar.com\/blog\/%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6\/","title":{"rendered":"\u0646\u0645\u0648\u062f\u0627\u0631\u0647\u0627 \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646 &#8211; \u062a\u0626\u0648\u0631\u06cc \u0648 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">\u0633\u0631\u0641\u0635\u0644\u0647\u0627\u06cc \u0645\u0637\u0644\u0628<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/rasanegaar.com\/blog\/%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6\/#%d8%a7%d9%84%da%af%d9%88%d8%b1%db%8c%d8%aa%d9%85_%d8%af%d8%a7%db%8c%da%a9%d8%b3%d8%aa%d8%b1%d8%a7_%e2%80%93_%d9%86%d8%b8%d8%b1%db%8c%d9%87_%d9%88_%d8%b4%d9%87%d9%88%d8%af\" >\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627 &#8211; \u0646\u0638\u0631\u06cc\u0647 \u0648 \u0634\u0647\u0648\u062f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/rasanegaar.com\/blog\/%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6\/#%d9%be%db%8c%d8%a7%d8%af%d9%87_%d8%b3%d8%a7%d8%b2%db%8c_%d8%a7%d9%84%da%af%d9%88%d8%b1%db%8c%d8%aa%d9%85_dijkstra_%d8%af%d8%b1_%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86\" >\u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/rasanegaar.com\/blog\/%d9%86%d9%85%d9%88%d8%af%d8%a7%d8%b1%d9%87%d8%a7-%d8%af%d8%b1-%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86-%d8%aa%d8%a6%d9%88%d8%b1%db%8c-%d9%88-%d9%be%db%8c%d8%a7%d8%af%d9%87-%d8%b3%d8%a7%d8%b2%db%8c-6\/#%d9%be%db%8c%da%86%db%8c%d8%af%da%af%db%8c_%d8%b2%d9%85%d8%a7%d9%86%db%8c\" >\u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc<\/a><\/li><\/ul><\/nav><\/div>\n<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">\u0632\u0645\u0627\u0646 \u0644\u0627\u0632\u0645 \u0628\u0631\u0627\u06cc \u0645\u0637\u0627\u0644\u0639\u0647: <\/span> <span class=\"rt-time\"> 7<\/span> <span class=\"rt-label rt-postfix\">\u062f\u0642\u06cc\u0642\u0647<\/span><\/span><p> <br \/>\n<\/p>\n<div><noscript><\/noscript><\/p>\n<p><strong>\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627<\/strong> \u0637\u0631\u0627\u062d\u06cc \u0634\u062f\u0647 \u0628\u0631\u0627\u06cc \u06cc\u0627\u0641\u062a\u0646 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631\u0647\u0627\u06cc \u0628\u06cc\u0646 <strong><em>\u06af\u0631\u0647 \u0647\u0627 \u062f\u0631 \u06cc\u06a9 \u0646\u0645\u0648\u062f\u0627\u0631<\/em><\/strong>.  \u0627\u06cc\u0646 \u062a\u0648\u0633\u0637 \u06cc\u06a9 \u062f\u0627\u0646\u0634\u0645\u0646\u062f \u06a9\u0627\u0645\u067e\u06cc\u0648\u062a\u0631 \u0647\u0644\u0646\u062f\u06cc\u060c Edsger Wybe Dijkstra\u060c \u062f\u0631 \u0633\u0627\u0644 1956\u060c \u0632\u0645\u0627\u0646\u06cc \u06a9\u0647 \u062f\u0631 \u062d\u0627\u0644 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0627\u0632 \u0631\u0648\u062a\u0631\u062f\u0627\u0645 \u0628\u0647 \u06af\u0631\u0648\u0646\u06cc\u0646\u06af\u0646 \u0628\u0648\u062f\u060c \u0637\u0631\u0627\u062d\u06cc \u0634\u062f.  \u0633\u0647 \u0633\u0627\u0644 \u0628\u0639\u062f \u0645\u0646\u062a\u0634\u0631 \u0634\u062f.<\/p>\n<div class=\"alert alert-note\">\n<div class=\"flex\">\n<div class=\"flex-shrink-0 mr-3\"><\/div>\n<div class=\"w-full\">\n<p><strong>\u062a\u0648\u062c\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f:<\/strong> \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u062f\u0631 \u0637\u0648\u0644 \u0633\u0627\u0644\u0647\u0627 \u0634\u0627\u0647\u062f \u062a\u063a\u06cc\u06cc\u0631\u0627\u062a\u06cc \u0628\u0648\u062f\u0647 \u0648 \u0646\u0633\u062e\u0647 \u0647\u0627 \u0648 \u062a\u063a\u06cc\u06cc\u0631\u0627\u062a \u0645\u062e\u062a\u0644\u0641\u06cc \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f.  \u062f\u0631 \u0627\u0635\u0644 &#8211; \u0628\u0631\u0627\u06cc \u0645\u062d\u0627\u0633\u0628\u0647 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0628\u06cc\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u062f <em>\u062f\u0648 \u06af\u0631\u0647<\/em>.  \u0628\u0627 \u062a\u0648\u062c\u0647 \u0628\u0647 \u0631\u0648\u0634 \u06a9\u0627\u0631 \u0622\u0646 &#8211; \u0628\u0631\u0627\u06cc \u0645\u062d\u0627\u0633\u0628\u0647 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0628\u06cc\u0646 \u06cc\u06a9 \u0634\u0631\u0648\u0639 \u062a\u0646\u0638\u06cc\u0645 \u0634\u062f\u0647 \u0627\u0633\u062a node \u0648 <em>\u06cc\u06a9\u06cc \u062f\u0631 \u0645\u06cc\u0627\u0646<\/em> node  \u062f\u0631 \u0646\u0645\u0648\u062f\u0627\u0631  \u0628\u0647 \u0627\u06cc\u0646 \u062a\u0631\u062a\u06cc\u0628 &#8211; \u0645\u06cc \u062a\u0648\u0627\u0646 \u0627\u0632 \u0622\u0646 \u0628\u0631\u0627\u06cc \u062a\u0648\u0644\u06cc\u062f \u0627\u0644\u0641 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f <strong>\u062f\u0631\u062e\u062a \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631<\/strong> \u06a9\u0647 \u0627\u0632 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0628\u06cc\u0646 \u062f\u0648 \u06af\u0631\u0647 \u062a\u0634\u06a9\u06cc\u0644 \u0634\u062f\u0647 \u0627\u0633\u062a\u060c <em>\u0647\u0645\u0686\u0646\u06cc\u0646<\/em> \u0645\u0627\u0646\u0646\u062f \u062a\u0645\u0627\u0645 \u06af\u0631\u0647 \u0647\u0627\u06cc \u062f\u06cc\u06af\u0631.  \u0633\u067e\u0633 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062f\u0631\u062e\u062a\u200c\u0647\u0627\u06cc\u06cc \u0631\u0627 \u06a9\u0647 \u0628\u0647 \u0622\u0646\u200c\u0647\u0627 \u0639\u0644\u0627\u0642\u0647 \u0646\u062f\u0627\u0631\u06cc\u062f\u060c \u0647\u0631\u0633 \u06a9\u0646\u06cc\u062f \u0648 \u06a9\u0648\u062a\u0627\u0647\u200c\u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0631\u0627 \u0628\u06cc\u0646 \u062f\u0648 \u06af\u0631\u0647 \u0628\u0647 \u062f\u0633\u062a \u0622\u0648\u0631\u06cc\u062f\u060c \u0627\u0645\u0627 \u0646\u0627\u06af\u0632\u06cc\u0631 \u0628\u0627\u06cc\u062f \u06a9\u0644 \u062f\u0631\u062e\u062a \u0631\u0627 \u0645\u062d\u0627\u0633\u0628\u0647 \u06a9\u0646\u06cc\u062f\u060c \u06a9\u0647 \u0627\u06cc\u0646 \u06cc\u06a9 \u0627\u0634\u06a9\u0627\u0644 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u0627\u0633\u062a \u06a9\u0647 \u0622\u0646 \u0631\u0627 \u0628\u0631\u0627\u06cc \u0622\u0646 \u0646\u0627\u0645\u0646\u0627\u0633\u0628 \u0645\u06cc\u200c\u06a9\u0646\u062f. <em>\u0628\u0632\u0631\u06af<\/em> \u0646\u0645\u0648\u062f\u0627\u0631\u0647\u0627<br \/>\u0645\u0627 \u062a\u0645\u0631\u06a9\u0632 \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f \u0631\u0648\u06cc \u0631\u0627 <strong>\u0627\u062c\u0631\u0627\u06cc \u062f\u0648\u0645 \u062f\u0631 \u062f\u0631\u0633<\/strong>.<\/p>\n<\/p><\/div><\/div><\/div>\n<blockquote>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u062f\u0631\u0633\u060c \u0646\u06af\u0627\u0647\u06cc \u0628\u0647 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra\u060c \u0634\u0647\u0648\u062f \u067e\u0634\u062a \u0622\u0646 \u0648 \u0633\u067e\u0633 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0622\u0646 \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646 \u062e\u0648\u0627\u0647\u06cc\u0645 \u062f\u0627\u0634\u062a.<\/p>\n<\/blockquote>\n<h3 id=\"dijkstrasalgorithmtheoryandintuition\"><span class=\"ez-toc-section\" id=\"%d8%a7%d9%84%da%af%d9%88%d8%b1%db%8c%d8%aa%d9%85_%d8%af%d8%a7%db%8c%da%a9%d8%b3%d8%aa%d8%b1%d8%a7_%e2%80%93_%d9%86%d8%b8%d8%b1%db%8c%d9%87_%d9%88_%d8%b4%d9%87%d9%88%d8%af\"><\/span>\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627 &#8211; \u0646\u0638\u0631\u06cc\u0647 \u0648 \u0634\u0647\u0648\u062f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627 \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u062f \u0631\u0648\u06cc \u0646\u0645\u0648\u062f\u0627\u0631\u0647\u0627\u06cc \u0628\u062f\u0648\u0646 \u062c\u0647\u062a\u060c \u0645\u062a\u0635\u0644\u060c \u0648\u0632\u0646 \u062f\u0627\u0631.<\/strong><\/p>\n<p>\u062f\u0631 \u0627\u0628\u062a\u062f\u0627\u060c \u0645\u0627 \u0645\u06cc \u062e\u0648\u0627\u0647\u06cc\u0645 \u0645\u062c\u0645\u0648\u0639\u0647 \u0627\u06cc \u0627\u0632 \u0631\u0626\u0648\u0633 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u0645 \u062a\u0627 \u062a\u0645\u0627\u0645 \u0631\u0626\u0648\u0633 \u0647\u0627\u06cc\u06cc \u0631\u0627 \u06a9\u0647 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0635\u062d\u06cc\u062d \u0628\u0647 \u0622\u0646\u0647\u0627 \u0627\u062e\u062a\u0635\u0627\u0635 \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0627\u0633\u062a\u060c \u067e\u06cc\u06af\u06cc\u0631\u06cc \u06a9\u0646\u06cc\u0645.  \u0647\u0645\u0686\u0646\u06cc\u0646 \u0628\u0627\u06cc\u062f \u00ab\u0647\u0632\u06cc\u0646\u0647\u200c\u0647\u0627\u00bb \u0631\u0627 \u0628\u0631\u0627\u06cc \u062a\u0645\u0627\u0645 \u0631\u0626\u0648\u0633 \u062f\u0631 \u0646\u0645\u0648\u062f\u0627\u0631 (\u0637\u0648\u0644 \u06a9\u0648\u062a\u0627\u0647\u200c\u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0641\u0639\u0644\u06cc \u06a9\u0647 \u0628\u0647 \u0622\u0646 \u0645\u0646\u062a\u0647\u06cc \u0645\u06cc\u200c\u0634\u0648\u062f) \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u0645.<\/p>\n<p>\u062a\u0645\u0627\u0645 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627 \u062a\u0639\u06cc\u06cc\u0646 \u062e\u0648\u0627\u0647\u062f \u0634\u062f <strong><em>&#8216;\u0628\u06cc \u0646\u0647\u0627\u06cc\u062a&#8217;<\/em><\/strong>  \u062f\u0631 \u0627\u0628\u062a\u062f\u0627 \u060c \u0628\u0631\u0627\u06cc \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0627\u0632 \u0627\u06cc\u0646 \u06a9\u0647 \u0647\u0631 \u0647\u0632\u06cc\u0646\u0647 \u062f\u06cc\u06af\u0631\u06cc \u06a9\u0647 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0622\u0646 \u0631\u0627 \u0628\u0627 \u0622\u0646 \u0645\u0642\u0627\u06cc\u0633\u0647 \u06a9\u0646\u06cc\u0645 \u060c \u06a9\u0648\u0686\u06a9\u062a\u0631 \u0627\u0632 \u0634\u0631\u0648\u0639 \u0627\u0633\u062a.  \u062a\u0646\u0647\u0627 \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u0647\u0632\u06cc\u0646\u0647 \u0627\u0648\u0644 \u060c \u0634\u0631\u0648\u0639 \u0631\u0627\u0633 \u0627\u0633\u062a &#8211; \u0627\u06cc\u0646 \u0631\u0627\u0633 \u0647\u0632\u06cc\u0646\u0647 0 \u062e\u0648\u0627\u0647\u062f \u062f\u0627\u0634\u062a \u060c \u0632\u06cc\u0631\u0627 \u0647\u06cc\u0686 \u0631\u0627\u0647\u06cc \u0628\u0631\u0627\u06cc \u062e\u0648\u062f\u0634 \u0646\u062f\u0627\u0631\u062f &#8211; node <code>s<\/code>.<\/p>\n<p>\u0633\u067e\u0633 \u060c \u0645\u0627 \u062f\u0648 \u0645\u0631\u062d\u0644\u0647 \u0627\u0635\u0644\u06cc \u0631\u0627 \u062a\u0627 \u0632\u0645\u0627\u0646\u06cc \u06a9\u0647 \u0646\u0645\u0648\u062f\u0627\u0631 \u0637\u06cc \u0634\u0648\u062f \u062a\u06a9\u0631\u0627\u0631 \u0645\u06cc \u06a9\u0646\u06cc\u0645 (\u062a\u0627 \u0632\u0645\u0627\u0646\u06cc \u06a9\u0647 \u0631\u0627\u0633 \u0647\u0627 \u0628\u062f\u0648\u0646 \u06a9\u0648\u062a\u0627\u0647\u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0627\u062e\u062a\u0635\u0627\u0635 \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0628\u0631\u0627\u06cc \u0622\u0646\u0647\u0627 \u0648\u062c\u0648\u062f \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u062f):<\/p>\n<ul>\n<li>\u0645\u0627 \u06cc\u06a9 \u0631\u0627\u0633 \u0631\u0627 \u0628\u0627 \u06a9\u0645\u062a\u0631\u06cc\u0646 \u0647\u0632\u06cc\u0646\u0647 \u0641\u0639\u0644\u06cc \u0627\u0646\u062a\u062e\u0627\u0628 \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u060c \u0627\u0632 \u0622\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0648 \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0645\u062c\u0645\u0648\u0639\u0647 \u0631\u0626\u0648\u0633 \u0647\u0627\u06cc \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0627\u0636\u0627\u0641\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/li>\n<li>\u0645\u0627 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627\u06cc \u062a\u0645\u0627\u0645 \u0631\u0626\u0648\u0633 \u0647\u0627\u06cc \u0645\u062c\u0627\u0648\u0631 \u0622\u0646 \u0631\u0627 \u06a9\u0647 \u0647\u0646\u0648\u0632 \u0628\u0627\u0632\u062f\u06cc\u062f \u0646\u0634\u062f\u0647 \u0627\u0633\u062a \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u06a9\u0646\u06cc\u0645.  \u0628\u0631\u0627\u06cc \u0647\u0631 \u0644\u0628\u0647 \u0628\u06cc\u0646 <code>n<\/code> \u0648 <code>m<\/code> \u062c\u0627\u06cc\u06cc \u06a9\u0647 <code>m<\/code> \u0628\u0627\u0632\u062f\u06cc\u062f \u0646\u0634\u062f\u0647 \u0627\u0633\u062a &#8211; \u0627\u06af\u0631 <code>cheapestPath(s, n)<\/code> + <code>cheapestPath(n,m)<\/code> < <code>cheapestPath(s,m)<\/code>\u060c \u0628\u0647 \u0631\u0648\u0632 \u0631\u0633\u0627\u0646\u06cc \u0627\u0631\u0632\u0627\u0646 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0628\u06cc\u0646 <code>s<\/code> \u0648 <code>m<\/code> \u0628\u0631\u0627\u0628\u0631 \u06a9\u0631\u062f\u0646 <code>cheapestPath(s,n)<\/code> + <code>cheapestPath(n,m)<\/code>.<\/li>\n<\/ul>\n<p>\u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 \u0627\u06cc\u0646 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u06a9\u0645\u06cc \u062f\u0634\u0648\u0627\u0631 \u0628\u0627\u0634\u062f \u06a9\u0647 \u0633\u0631 \u062e\u0648\u062f \u0631\u0627 \u0628\u067e\u06cc\u0686\u06cc\u062f &#8211; \u0628\u06cc\u0627\u06cc\u06cc\u062f process \u0642\u0628\u0644 \u0627\u0632 \u0627\u062c\u0631\u0627\u06cc \u0622\u0646!  \u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u06cc\u06a9 \u0646\u0645\u0648\u062f\u0627\u0631 \u0628\u062f\u0648\u0646 \u062c\u0647\u062a\u060c \u0648\u0632\u0646 \u062f\u0627\u0631 \u0648 \u0645\u062a\u0635\u0644 \u0622\u0645\u062f\u0647 \u0627\u0633\u062a:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-1.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 1\" title=\"\"><\/p>\n<p>\u0627\u06cc\u0646 \u0631\u0627 \u0628\u06af\u0648\u06cc\u06cc\u0645 <em>\u0631\u0627\u0633 0<\/em> \u0646\u0642\u0637\u0647 \u0634\u0631\u0648\u0639 \u0645\u0627 \u0627\u0633\u062a  \u0645\u0627 \u0642\u0635\u062f \u062f\u0627\u0631\u06cc\u0645 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627\u06cc \u0627\u0648\u0644\u06cc\u0647 \u0631\u0627\u0633 \u0647\u0627 \u0631\u0627 \u062f\u0631 \u0627\u06cc\u0646 \u0646\u0645\u0648\u062f\u0627\u0631 \u0628\u0647 Infinity \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u0645 \u060c \u0628\u0647 \u062c\u0632 \u0631\u0627\u0633 \u0634\u0631\u0648\u0639:<\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>inf<\/td>\n<\/tr>\n<\/table>\n<p>\u0645\u0627 \u0631\u0627\u0633 \u0631\u0627 \u0628\u0627 \u062d\u062f\u0627\u0642\u0644 \u0647\u0632\u06cc\u0646\u0647 \u0627\u0646\u062a\u062e\u0627\u0628 \u0645\u06cc \u06a9\u0646\u06cc\u0645 &#8211; \u06cc\u0639\u0646\u06cc <em>\u0631\u0627\u0633 0<\/em>.  \u0645\u0627 \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0639\u0644\u0627\u0645\u062a \u06af\u0630\u0627\u0631\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0648 \u0628\u0647 \u0645\u062c\u0645\u0648\u0639\u0647 \u0631\u0626\u0648\u0633 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u062e\u0648\u062f \u0627\u0636\u0627\u0641\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645.  \u0634\u0631\u0648\u0639 node \u0627\u0631\u0627\u062f\u0647 <em>\u0647\u0645\u06cc\u0634\u0647<\/em> \u06a9\u0645\u062a\u0631\u06cc\u0646 \u0647\u0632\u06cc\u0646\u0647 \u0631\u0627 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f \u062a\u0627 \u0647\u0645\u06cc\u0634\u0647 \u0627\u0648\u0644\u06cc\u0646 \u06a9\u0633\u06cc \u0628\u0627\u0634\u062f \u06a9\u0647 \u0627\u0636\u0627\u0641\u0647 \u0645\u06cc \u0634\u0648\u062f:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-2.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 2\" title=\"\"><\/p>\n<p>\u0633\u067e\u0633 \u060c \u0647\u0632\u06cc\u0646\u0647 \u0631\u0626\u0648\u0633 \u0647\u0627\u06cc \u0645\u062c\u0627\u0648\u0631 (1 \u0648 6) \u0631\u0627 \u0628\u0647 \u0631\u0648\u0632 \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f.  \u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 <code>0 + 4 &lt; infinity<\/code> \u0648 <code>0 + 7 &lt; infinity<\/code>\u060c \u0645\u0627 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627 \u0631\u0627 \u0628\u0647 \u0627\u06cc\u0646 \u0631\u0626\u0648\u0633 \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u06a9\u0646\u06cc\u0645:<\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>inf<\/td>\n<\/tr>\n<\/table>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u0627\u0632 \u06a9\u0648\u0686\u06a9\u062a\u0631\u06cc\u0646 \u0631\u0627\u0633 \u0647\u0632\u06cc\u0646\u0647 \u0628\u0639\u062f\u06cc \u0628\u0627\u0632\u062f\u06cc\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645.  \u0648\u0632\u0646 \u0627\u0632 <em>4<\/em> \u06a9\u0645\u062a\u0631 \u0627\u0632 <em>7<\/em> \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u0645\u0627 \u0628\u0647 <em>\u0631\u0627\u0633 1<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-3.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 3\" title=\"\"><\/p>\n<p>\u067e\u0633 \u0627\u0632 \u067e\u06cc\u0645\u0627\u06cc\u0634\u060c \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0639\u0644\u0627\u0645\u062a \u06af\u0630\u0627\u0631\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0648 \u0633\u067e\u0633 \u0631\u0626\u0648\u0633 \u0645\u062c\u0627\u0648\u0631 \u0631\u0627 \u0645\u0634\u0627\u0647\u062f\u0647 \u0648 \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u06a9\u0646\u06cc\u0645: 2\u060c 6\u060c \u0648 7:<\/p>\n<ul>\n<li>\u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 <code>4 + 9 &lt; infinity<\/code>\u060c \u0647\u0632\u06cc\u0646\u0647 \u062c\u062f\u06cc\u062f \u0631\u0627\u0633 2 13 \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f<\/li>\n<li>\u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 <code>4 + 11 &gt; 7<\/code>\u060c \u0647\u0632\u06cc\u0646\u0647 \u0631\u0627\u0633 6 7 \u0628\u0627\u0642\u06cc \u0645\u06cc \u0645\u0627\u0646\u062f<\/li>\n<li>\u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 <code>4 + 20 &lt; infinity<\/code>\u060c \u0647\u0632\u06cc\u0646\u0647 \u062c\u062f\u06cc\u062f \u0631\u0627\u0633 7 24 \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f<\/li>\n<\/ul>\n<p>\u0627\u06cc\u0646\u0647\u0627 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627\u06cc \u062c\u062f\u06cc\u062f \u0645\u0627 \u0647\u0633\u062a\u0646\u062f:<\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>24<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>inf<\/td>\n<\/tr>\n<\/table>\n<p>\u0631\u0627\u0633 \u0628\u0639\u062f\u06cc \u06a9\u0647 \u0642\u0631\u0627\u0631 \u0627\u0633\u062a \u0627\u0632 \u0622\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u06a9\u0646\u06cc\u0645 \u0627\u06cc\u0646 \u0627\u0633\u062a <em>\u0631\u0627\u0633 6<\/em>.  \u0645\u0627 \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0639\u0644\u0627\u0645\u062a \u06af\u0630\u0627\u0631\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0648 \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627\u06cc \u0631\u0626\u0648\u0633 \u0645\u062c\u0627\u0648\u0631 \u0622\u0646 \u0631\u0627 \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u06a9\u0646\u06cc\u0645:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-4.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 4\" title=\"\"><\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>7<\/b><\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>inf<\/td>\n<\/tr>\n<\/table>\n<p>\u0627\u06cc\u0646 process \u0627\u062f\u0627\u0645\u0647 \u062f\u0627\u0631\u062f \u0628\u0647 <em>\u0631\u0627\u0633 7<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-5.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 5\" title=\"\"><\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>inf<\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>7<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>7<\/b><\/td>\n<td><b>8<\/b><\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>11<\/td>\n<\/tr>\n<\/table>\n<p>\u0648 \u062f\u0648\u0628\u0627\u0631\u0647\u060c \u0628\u0647 <em>\u0631\u0627\u0633 4<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-6.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 6\" title=\"\"><\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>19<\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><b>9<\/b><\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>24<\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>7<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>7<\/b><\/td>\n<td><b>8<\/b><\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>11<\/td>\n<\/tr>\n<\/table>\n<p>\u0648 \u062f\u0648\u0628\u0627\u0631\u0647\u060c \u0628\u0647 <em>\u0631\u0627\u0633 2<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-7.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 7\" title=\"\"><\/p>\n<p>\u062a\u0646\u0647\u0627 \u0631\u0623\u0633\u06cc \u06a9\u0647 \u0645\u06cc \u062e\u0648\u0627\u0647\u06cc\u0645 \u062f\u0631 \u0646\u0638\u0631 \u0628\u06af\u06cc\u0631\u06cc\u0645 \u0627\u06cc\u0646 \u0627\u0633\u062a <em>\u0631\u0627\u0633 3<\/em>.  \u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 <code>11 + 6 &lt; 19<\/code>\u060c \u0647\u0632\u06cc\u0646\u0647 \u0631\u0627\u0633 3 \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<p>\u0633\u067e\u0633\u060c \u0628\u0647 \u0627\u062f\u0627\u0645\u0647 \u0645\u06cc\u200c\u062f\u0647\u06cc\u0645 <em>\u0631\u0627\u0633 8<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-8.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 8\" title=\"\"><\/p>\n<p>\u062f\u0631 \u0646\u0647\u0627\u06cc\u062a\u060c \u0645\u0627 \u062f\u0631 \u062d\u0627\u0644 \u0628\u0647 \u0631\u0648\u0632 \u0631\u0633\u0627\u0646\u06cc <em>\u0631\u0627\u0633 5<\/em>:<\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>11<\/b><\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>17<\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><b>9<\/b><\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>24<\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>7<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>7<\/b><\/td>\n<td><b>8<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>8<\/b><\/td>\n<td><b>11<\/b><\/td>\n<\/tr>\n<\/table>\n<p>\u0645\u0627 \u0631\u0626\u0648\u0633 \u0633\u0627\u062e\u062a\u0627\u0631 \u062d\u0644\u0642\u0647 \u0645\u0627\u0646\u0646\u062f \u0631\u0627 \u062f\u0631 \u067e\u0627\u06cc\u0627\u0646 \u0628\u0647 \u0631\u0648\u0632 \u06a9\u0631\u062f\u0647 \u0627\u06cc\u0645 &#8211; \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u0627\u06a9\u0646\u0648\u0646 \u0641\u0642\u0637 \u0628\u0627\u06cc\u062f \u0627\u0632 \u0622\u0646 \u0639\u0628\u0648\u0631 \u06a9\u0646\u06cc\u0645 &#8211; \u0627\u0628\u062a\u062f\u0627 <em>\u0631\u0627\u0633 3<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-9.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 9\" title=\"\"><\/p>\n<p>\u0648 \u062f\u0631 \u0646\u0647\u0627\u06cc\u062a\u060c \u0628\u0647 <em>\u0631\u0627\u0633 5<\/em>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rasanegar.com\/blog\/wp-content\/uploads\/2024\/01\/dijkstras-algorithm-in-python-10.png\" alt=\"dijkstra \u0645\u0631\u062d\u0644\u0647 10\" title=\"\"><\/p>\n<p>\u0647\u06cc\u0686 \u0631\u0626\u0648\u0633 \u0628\u0627\u0632\u062f\u06cc\u062f \u0646\u0634\u062f\u0647 \u062f\u06cc\u06af\u0631\u06cc \u0648\u062c\u0648\u062f \u0646\u062f\u0627\u0631\u062f \u06a9\u0647 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0646\u06cc\u0627\u0632 \u0628\u0647 \u0628\u0647 \u0631\u0648\u0632 \u0631\u0633\u0627\u0646\u06cc \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u062f.  \u0647\u0632\u06cc\u0646\u0647 \u0647\u0627\u06cc \u0646\u0647\u0627\u06cc\u06cc \u0645\u0627 \u0646\u0634\u0627\u0646 \u062f\u0647\u0646\u062f\u0647 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631\u0647\u0627 \u0627\u0633\u062a node 0 \u0628\u0647 \u0647\u0631 \u062f\u06cc\u06af\u0631\u06cc node \u062f\u0631 \u0646\u0645\u0648\u062f\u0627\u0631:<\/p>\n<table class=\"table table-striped\">\n<tr>\n<th>\u0631\u0627\u0633<\/th>\n<th>\u0647\u0632\u06cc\u0646\u0647 \u0631\u0633\u06cc\u062f\u0646 \u0628\u0647 \u0622\u0646 \u0627\u0632 \u0631\u0627\u0633 0<\/th>\n<\/tr>\n<tr>\n<td><b>0<\/b><\/td>\n<td><b>0<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>1<\/b><\/td>\n<td><b>4<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>2<\/b><\/td>\n<td><b>11<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>3<\/b><\/td>\n<td><b>17<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>4<\/b><\/td>\n<td><b>9<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>5<\/b><\/td>\n<td><b>24<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>6<\/b><\/td>\n<td><b>7<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>7<\/b><\/td>\n<td><b>8<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>8<\/b><\/td>\n<td><b>11<\/b><\/td>\n<\/tr>\n<\/table>\n<p>\u0634\u0645\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0627\u06cc\u0646 \u062c\u062f\u0648\u0644 \u0631\u0627 \u0647\u0631\u0633 \u06a9\u0646\u06cc\u062f \u0648 \u0641\u0642\u0637 \u0641\u0627\u0635\u0644\u0647 \u0628\u06cc\u0646 *\u06af\u0631\u0647 X* \u0648 *\u06af\u0631\u0647 Y* \u0631\u0627 \u062d\u0641\u0638 \u06a9\u0646\u06cc\u062f\u060c \u0647\u0631\u0686\u0646\u062f\u060c \u0628\u0647 \u0647\u0631 \u062d\u0627\u0644 \u0628\u0627\u06cc\u062f \u0627\u06cc\u0646 \u0645\u062d\u0627\u0633\u0628\u0647 \u0631\u0627 \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f \u062a\u0627 \u0648\u0627\u0642\u0639\u0627\u064b \u0647\u0632\u06cc\u0646\u0647 \u0645\u062d\u0627\u0633\u0628\u0627\u062a\u06cc \u0631\u0627 \u06a9\u0627\u0647\u0634 \u0646\u062f\u0647\u06cc\u062f.<\/p>\n<h3 id=\"implementdijkstrasalgorithminpython\"><span class=\"ez-toc-section\" id=\"%d9%be%db%8c%d8%a7%d8%af%d9%87_%d8%b3%d8%a7%d8%b2%db%8c_%d8%a7%d9%84%da%af%d9%88%d8%b1%db%8c%d8%aa%d9%85_dijkstra_%d8%af%d8%b1_%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86\"><\/span>\u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u062d\u0627\u0644\u0627 \u06a9\u0647 \u0645\u0631\u062d\u0644\u0647 \u0628\u0647 \u0645\u0631\u062d\u0644\u0647 \u0631\u0627 \u0645\u0631\u0648\u0631 \u06a9\u0631\u062f\u06cc\u0645 process\u060c \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0628\u0628\u06cc\u0646\u06cc\u0645 \u0686\u06af\u0648\u0646\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u0631\u0627 \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u06a9\u0646\u06cc\u0645!  \u0628\u0631\u0627\u06cc \u0645\u0631\u062a\u0628\u200c\u0633\u0627\u0632\u06cc \u0648 \u067e\u06cc\u06af\u06cc\u0631\u06cc \u0631\u0626\u0648\u0633\u200c\u0647\u0627\u06cc\u06cc \u06a9\u0647 \u0647\u0646\u0648\u0632 \u0628\u0627\u0632\u062f\u06cc\u062f \u0646\u06a9\u0631\u062f\u0647\u200c\u0627\u06cc\u0645 &#8211; \u0627\u0632 a \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u06a9\u0646\u06cc\u0645 <code>PriorityQueue<\/code>:<\/p>\n<pre><code class=\"hljs\"><span class=\"hljs-keyword\">from<\/span> queue <span class=\"hljs-keyword\">import<\/span> PriorityQueue\n<\/code><\/pre>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u06cc\u06a9 \u0633\u0627\u0632\u0646\u062f\u0647 \u0628\u0631\u0627\u06cc \u06a9\u0644\u0627\u0633\u06cc \u0628\u0647 \u0646\u0627\u0645 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 <code>Graph<\/code>:<\/p>\n<pre><code class=\"hljs\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Graph<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span>(<span class=\"hljs-params\">self, num_of_vertices<\/span>):<\/span>\n        self.v = num_of_vertices\n        self.edges = ((-<span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">range<\/span>(num_of_vertices)) <span class=\"hljs-keyword\">for<\/span> j <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">range<\/span>(num_of_vertices))\n        self.visited = ()\n<\/code><\/pre>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u0633\u0627\u0632\u0646\u062f\u0647 \u067e\u0627\u0631\u0627\u0645\u062a\u0631\u06cc \u0633\u0627\u062f\u0647\u060c \u062a\u0639\u062f\u0627\u062f \u0631\u0626\u0648\u0633 \u0646\u0645\u0648\u062f\u0627\u0631 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0622\u0631\u06af\u0648\u0645\u0627\u0646 \u0627\u0631\u0627\u0626\u0647 \u06a9\u0631\u062f\u06cc\u0645 \u0648 \u0633\u0647 \u0641\u06cc\u0644\u062f \u0631\u0627 \u0645\u0642\u062f\u0627\u0631\u062f\u0647\u06cc \u0627\u0648\u0644\u06cc\u0647 \u06a9\u0631\u062f\u06cc\u0645:<\/p>\n<ul>\n<li><code>v<\/code>: \u062a\u0639\u062f\u0627\u062f \u0631\u0626\u0648\u0633 \u0646\u0645\u0648\u062f\u0627\u0631 \u0631\u0627 \u0646\u0634\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f.<\/li>\n<li><code>edges<\/code>: \u0641\u0647\u0631\u0633\u062a \u06cc\u0627\u0644 \u0647\u0627 \u0631\u0627 \u0628\u0647 \u0635\u0648\u0631\u062a \u0645\u0627\u062a\u0631\u06cc\u0633 \u0646\u0634\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f.  \u0628\u0631\u0627\u06cc \u06af\u0631\u0647 \u0647\u0627 <code>u<\/code> \u0648 <code>v<\/code>\u060c <code>self.edges(u)(v) = weight<\/code> \u0627\u0632 \u0644\u0628\u0647<\/li>\n<li><code>visited<\/code>: \u0645\u062c\u0645\u0648\u0639\u0647 \u0627\u06cc \u06a9\u0647 \u0634\u0627\u0645\u0644 \u0631\u0626\u0648\u0633 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0627\u0633\u062a.<\/li>\n<\/ul>\n<p>\u062d\u0627\u0644\u0627 \u0628\u06cc\u0627\u06cc\u06cc\u062f \u062a\u0627\u0628\u0639\u06cc \u0631\u0627 \u062a\u0639\u0631\u06cc\u0641 \u06a9\u0646\u06cc\u0645 \u06a9\u0647 \u06cc\u06a9 \u06cc\u0627\u0644 \u0628\u0647 \u0646\u0645\u0648\u062f\u0627\u0631 \u0627\u0636\u0627\u0641\u0647 \u0645\u06cc \u06a9\u0646\u062f:<\/p>\n<pre><code class=\"hljs\">    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">add_edge<\/span>(<span class=\"hljs-params\">self, u, v, weight<\/span>):<\/span>\n        self.edges(u)(v) = weight\n        self.edges(v)(u) = weight\n<\/code><\/pre>\n<p>\u0628\u0627 \u062a\u0639\u0631\u06cc\u0641 \u06af\u0631\u0627\u0641 \u0645\u0627 \u062e\u0627\u0631\u062c \u0627\u0632 \u0645\u0633\u06cc\u0631 &#8211; \u0628\u06cc\u0627\u06cc\u06cc\u062f \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u0631\u0627 \u062a\u0639\u0631\u06cc\u0641 \u06a9\u0646\u06cc\u0645:<\/p>\n<pre><code class=\"hljs\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">dijkstra<\/span>(<span class=\"hljs-params\">graph, start_vertex<\/span>):<\/span>\n    D = {v:<span class=\"hljs-built_in\">float<\/span>(<span class=\"hljs-string\">'inf'<\/span>) <span class=\"hljs-keyword\">for<\/span> v <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">range<\/span>(graph.v)}\n    D(start_vertex) = <span class=\"hljs-number\">0<\/span>\n\n    pq = PriorityQueue()\n    pq.put((<span class=\"hljs-number\">0<\/span>, start_vertex))\n\n    <span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-keyword\">not<\/span> pq.empty():\n        (dist, current_vertex) = pq.get()\n        graph.visited.append(current_vertex)\n\n        <span class=\"hljs-keyword\">for<\/span> neighbor <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">range<\/span>(graph.v):\n            <span class=\"hljs-keyword\">if<\/span> graph.edges(current_vertex)(neighbor) != -<span class=\"hljs-number\">1<\/span>:\n                distance = graph.edges(current_vertex)(neighbor)\n                <span class=\"hljs-keyword\">if<\/span> neighbor <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-keyword\">in<\/span> graph.visited:\n                    old_cost = D(neighbor)\n                    new_cost = D(current_vertex) + distance\n                    <span class=\"hljs-keyword\">if<\/span> new_cost &lt; old_cost:\n                        pq.put((new_cost, neighbor))\n                        D(neighbor) = new_cost\n    <span class=\"hljs-keyword\">return<\/span> D\n<\/code><\/pre>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u06a9\u062f \u0627\u0628\u062a\u062f\u0627 \u06cc\u06a9 \u0644\u06cc\u0633\u062a \u0627\u06cc\u062c\u0627\u062f \u06a9\u0631\u062f\u06cc\u0645 <code>D<\/code> \u0627\u0632 \u0627\u0646\u062f\u0627\u0632\u0647 <code>v<\/code>.  \u06a9\u0644 \u0644\u06cc\u0633\u062a \u0628\u0647 \u0628\u06cc \u0646\u0647\u0627\u06cc\u062a \u0645\u0642\u062f\u0627\u0631 \u062f\u0647\u06cc \u0627\u0648\u0644\u06cc\u0647 \u0645\u06cc \u0634\u0648\u062f.  \u0627\u06cc\u0646 \u0644\u06cc\u0633\u062a\u06cc \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f \u06a9\u0647 \u0645\u0627 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631\u0647\u0627 \u0631\u0627 \u0627\u0632 \u0622\u0646 \u062f\u0648\u0631 \u0645\u06cc \u06a9\u0646\u06cc\u0645 <code>start_vertex<\/code> \u0628\u0647 \u062a\u0645\u0627\u0645 \u06af\u0631\u0647 \u0647\u0627\u06cc \u062f\u06cc\u06af\u0631<\/p>\n<p>\u0645\u0642\u062f\u0627\u0631 \u0631\u0627\u0633 \u0634\u0631\u0648\u0639 \u0631\u0627 \u0631\u0648\u06cc 0 \u0642\u0631\u0627\u0631 \u0645\u06cc \u062f\u0647\u06cc\u0645\u060c \u0632\u06cc\u0631\u0627 \u0641\u0627\u0635\u0644\u0647 \u0622\u0646 \u0627\u0632 \u062e\u0648\u062f\u0634 \u0627\u0633\u062a.  \u0633\u067e\u0633\u060c \u06cc\u06a9 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a \u0631\u0627 \u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc \u0645\u06cc\u200c\u06a9\u0646\u06cc\u0645\u060c \u06a9\u0647 \u0627\u0632 \u0622\u0646 \u0628\u0631\u0627\u06cc \u0645\u0631\u062a\u0628\u200c\u0633\u0627\u0632\u06cc \u0633\u0631\u06cc\u0639 \u0631\u0627\u0633\u200c\u0647\u0627 \u0627\u0632 \u06a9\u0645\u062a\u0631\u06cc\u0646 \u0628\u0647 \u062f\u0648\u0631\u062a\u0631\u06cc\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u06a9\u0646\u06cc\u0645.  \u0631\u0627\u0633 \u0634\u0631\u0648\u0639 \u0631\u0627 \u062f\u0631 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a \u0642\u0631\u0627\u0631 \u0645\u06cc \u062f\u0647\u06cc\u0645.  \u062d\u0627\u0644\u060c \u0628\u0631\u0627\u06cc \u0647\u0631 \u0631\u0623\u0633 \u062f\u0631 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a\u060c \u0627\u0628\u062a\u062f\u0627 \u0622\u0646\u0647\u0627 \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0628\u0627\u0632\u062f\u06cc\u062f \u0634\u062f\u0647 \u0639\u0644\u0627\u0645\u062a \u06af\u0630\u0627\u0631\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0648 \u0633\u067e\u0633 \u0627\u0632 \u0637\u0631\u06cc\u0642 \u0647\u0645\u0633\u0627\u06cc\u06af\u0627\u0646 \u0622\u0646\u0647\u0627 \u062a\u06a9\u0631\u0627\u0631 \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/p>\n<p>\u062f\u0631 \u0635\u0648\u0631\u062a \u0639\u062f\u0645 \u0645\u0631\u0627\u062c\u0639\u0647 \u0628\u0647 \u0647\u0645\u0633\u0627\u06cc\u0647 \u0647\u0632\u06cc\u0646\u0647 \u0642\u062f\u06cc\u0645\u06cc \u0648 \u062c\u062f\u06cc\u062f \u0631\u0627 \u0628\u0627 \u0647\u0645 \u0645\u0642\u0627\u06cc\u0633\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645.  \u0647\u0632\u06cc\u0646\u0647 \u0642\u062f\u06cc\u0645\u06cc \u0645\u0642\u062f\u0627\u0631 \u0641\u0639\u0644\u06cc \u06a9\u0648\u062a\u0627\u0647\u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0627\u0632 \u0631\u0627\u0633 \u0634\u0631\u0648\u0639 \u0628\u0647 \u0647\u0645\u0633\u0627\u06cc\u0647 \u0627\u0633\u062a\u060c \u062f\u0631 \u062d\u0627\u0644\u06cc \u06a9\u0647 \u0647\u0632\u06cc\u0646\u0647 \u062c\u062f\u06cc\u062f \u0645\u0642\u062f\u0627\u0631 \u0645\u062c\u0645\u0648\u0639 \u06a9\u0648\u062a\u0627\u0647\u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0627\u0632 \u0631\u0627\u0633 \u0634\u0631\u0648\u0639 \u0628\u0647 \u0631\u0627\u0633 \u0641\u0639\u0644\u06cc \u0648 \u0641\u0627\u0635\u0644\u0647 \u0628\u06cc\u0646 \u0631\u0627\u0633 \u0641\u0639\u0644\u06cc \u0648 \u0631\u0627\u0633 \u0641\u0639\u0644\u06cc \u0627\u0633\u062a. \u0647\u0645\u0633\u0627\u06cc\u0647  \u0627\u06af\u0631 \u0647\u0632\u06cc\u0646\u0647 \u062c\u062f\u06cc\u062f \u06a9\u0645\u062a\u0631 \u0627\u0632 \u0647\u0632\u06cc\u0646\u0647 \u0642\u0628\u0644\u06cc \u0628\u0627\u0634\u062f\u060c \u0647\u0645\u0633\u0627\u06cc\u0647 \u0648 \u0647\u0632\u06cc\u0646\u0647 \u0622\u0646 \u0631\u0627 \u062f\u0631 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a \u0642\u0631\u0627\u0631 \u0645\u06cc \u062f\u0647\u06cc\u0645 \u0648 \u0644\u06cc\u0633\u062a\u06cc \u0631\u0627 \u06a9\u0647 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631\u0647\u0627 \u0631\u0627 \u062f\u0631 \u0622\u0646 \u0646\u06af\u0647 \u0645\u06cc \u062f\u0627\u0631\u06cc\u0645\u060c \u0628\u0647 \u0631\u0648\u0632 \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/p>\n<p>\u062f\u0631 \u0646\u0647\u0627\u06cc\u062a\u060c \u067e\u0633 \u0627\u0632 \u0628\u0627\u0632\u062f\u06cc\u062f \u0647\u0645\u0647 \u0631\u0626\u0648\u0633 \u0648 \u062e\u0627\u0644\u06cc \u0634\u062f\u0646 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a\u060c \u0644\u06cc\u0633\u062a \u0631\u0627 \u0628\u0631\u0645\u06cc \u06af\u0631\u062f\u0627\u0646\u06cc\u0645 <code>D<\/code>.<\/p>\n<p>\u0628\u06cc\u0627\u06cc\u06cc\u062f \u0646\u0645\u0648\u062f\u0627\u0631\u06cc \u0631\u0627 \u06a9\u0647 \u0642\u0628\u0644\u0627\u064b \u0628\u0631\u0627\u06cc \u062a\u0623\u06cc\u06cc\u062f \u0645\u0631\u0627\u062d\u0644 \u062f\u0633\u062a\u06cc \u062e\u0648\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0647\u200c\u0627\u06cc\u0645 \u0645\u0642\u062f\u0627\u0631\u062f\u0647\u06cc \u0627\u0648\u0644\u06cc\u0647 \u06a9\u0646\u06cc\u0645 \u0648 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u0631\u0627 \u0622\u0632\u0645\u0627\u06cc\u0634 \u06a9\u0646\u06cc\u0645:<\/p>\n<pre><code class=\"hljs\">g = Graph(<span class=\"hljs-number\">9<\/span>)\ng.add_edge(<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">4<\/span>)\ng.add_edge(<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">6<\/span>, <span class=\"hljs-number\">7<\/span>)\ng.add_edge(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">6<\/span>, <span class=\"hljs-number\">11<\/span>)\ng.add_edge(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">20<\/span>)\ng.add_edge(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">9<\/span>)\ng.add_edge(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">3<\/span>, <span class=\"hljs-number\">6<\/span>)\ng.add_edge(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">2<\/span>)\ng.add_edge(<span class=\"hljs-number\">3<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">10<\/span>)\ng.add_edge(<span class=\"hljs-number\">3<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">5<\/span>)\ng.add_edge(<span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">15<\/span>)\ng.add_edge(<span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">1<\/span>)\ng.add_edge(<span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">8<\/span>, <span class=\"hljs-number\">5<\/span>)\ng.add_edge(<span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">8<\/span>, <span class=\"hljs-number\">12<\/span>)\ng.add_edge(<span class=\"hljs-number\">6<\/span>, <span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">1<\/span>)\ng.add_edge(<span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">8<\/span>, <span class=\"hljs-number\">3<\/span>) \n<\/code><\/pre>\n<p>\u0627\u06a9\u0646\u0648\u0646 \u0628\u0647 \u0633\u0627\u062f\u06af\u06cc \u062a\u0627\u0628\u0639\u06cc \u0631\u0627 \u06a9\u0647 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627 \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u062f\u0647\u062f \u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u0631\u0648\u06cc \u0627\u06cc\u0646 \u0646\u0645\u0648\u062f\u0627\u0631 \u0648 print \u0627\u0632 \u0646\u062a\u0627\u06cc\u062c:<\/p>\n<pre><code class=\"hljs\">D = dijkstra(g, <span class=\"hljs-number\">0<\/span>)\n\n<span class=\"hljs-built_in\">print<\/span>(D)\n\n<\/code><\/pre>\n<p>\u06cc\u0627\u060c \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u0645 \u0622\u0646 \u0631\u0627 \u06a9\u0645\u06cc \u0632\u06cc\u0628\u0627\u062a\u0631 \u0642\u0627\u0644\u0628 \u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u0645:<\/p>\n<pre><code class=\"hljs\"><span class=\"hljs-keyword\">for<\/span> vertex <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">range<\/span>(<span class=\"hljs-built_in\">len<\/span>(D)):\n    <span class=\"hljs-built_in\">print<\/span>(<span class=\"hljs-string\">\"Distance from vertex 0 to vertex\"<\/span>, vertex, <span class=\"hljs-string\">\"is\"<\/span>, D(vertex))\n<\/code><\/pre>\n<p>\u067e\u0633 \u0627\u0632 \u06a9\u0627\u0645\u067e\u0627\u06cc\u0644 \u0628\u0631\u0646\u0627\u0645\u0647\u060c \u0627\u06cc\u0646 \u062e\u0631\u0648\u062c\u06cc \u0631\u0627 \u062f\u0631\u06cc\u0627\u0641\u062a \u0645\u06cc \u06a9\u0646\u06cc\u0645:<\/p>\n<pre><code class=\"hljs\">Distance from vertex 0 to vertex 0 is 0\nDistance from vertex 0 to vertex 1 is 4\nDistance from vertex 0 to vertex 2 is 11\nDistance from vertex 0 to vertex 3 is 17\nDistance from vertex 0 to vertex 4 is 9\nDistance from vertex 0 to vertex 5 is 22\nDistance from vertex 0 to vertex 6 is 7\nDistance from vertex 0 to vertex 7 is 8\nDistance from vertex 0 to vertex 8 is 11\n<\/code><\/pre>\n<p>\u0641\u0627\u0635\u0644\u0647 \u0628\u06cc\u0646 \u0634\u0631\u0648\u0639 node \u0648 \u06cc\u06a9\u062f\u06cc\u06af\u0631 node \u062f\u0631 \u062f\u0631\u062e\u062a \u0645\u062d\u0627\u0633\u0628\u0647 \u0648 \u062e\u0631\u0648\u062c\u06cc \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<h3 id=\"timecomplexity\"><span class=\"ez-toc-section\" id=\"%d9%be%db%8c%da%86%db%8c%d8%af%da%af%db%8c_%d8%b2%d9%85%d8%a7%d9%86%db%8c\"><\/span>\u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u0647\u0631 \u06cc\u0627\u0644 \u0631\u0627 \u06cc\u06a9 \u0628\u0627\u0631 \u0631\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u06a9\u0647 \u0646\u062a\u06cc\u062c\u0647 \u0622\u0646 \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc \u0627\u0633\u062a <code>O(|E|)<\/code>\u060c \u062c\u0627\u06cc\u06cc \u06a9\u0647 <code>|E|<\/code> \u062a\u0639\u062f\u0627\u062f \u0644\u0628\u0647 \u0647\u0627 \u0631\u0627 \u0646\u0634\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f.<\/p>\n<p>\u0627\u0632 \u0647\u0631 \u06a9\u062f\u0627\u0645 \u0647\u0645 \u0628\u0627\u0632\u062f\u06cc\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645 node \u06cc\u06a9 \u0628\u0627\u0631 \u06a9\u0647 \u0645\u0646\u062c\u0631 \u0628\u0647 \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc \u0645\u06cc \u0634\u0648\u062f <code>O(|V|)<\/code>\u060c \u062c\u0627\u06cc\u06cc \u06a9\u0647 <code>|V|<\/code> \u062a\u0639\u062f\u0627\u062f \u0631\u0626\u0648\u0633 \u0631\u0627 \u0646\u0634\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f.  \u0647\u0631 \u0631\u0627\u0633 \u062f\u0631 \u06cc\u06a9 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a \u0642\u0631\u0627\u0631 \u0645\u06cc \u06af\u06cc\u0631\u062f\u060c \u062c\u0627\u06cc\u06cc \u06a9\u0647 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062f\u0646 \u0646\u0632\u062f\u06cc\u06a9\u062a\u0631\u06cc\u0646 \u0631\u0627\u0633 \u0628\u0639\u062f\u06cc \u0628\u0647 \u0635\u0648\u0631\u062a \u062b\u0627\u0628\u062a \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u0634\u0648\u062f. <code>O(1)<\/code> \u0632\u0645\u0627\u0646.  \u0628\u0627 \u0627\u06cc\u0646 \u062d\u0627\u0644\u060c \u0645\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645 <code>O(Vlog|V|)<\/code> \u0632\u0645\u0627\u0646 \u0645\u0631\u062a\u0628 \u06a9\u0631\u062f\u0646 \u0631\u0626\u0648\u0633 \u062f\u0631 \u0627\u06cc\u0646 \u0635\u0641 \u0627\u0648\u0644\u0648\u06cc\u062a \u0627\u0633\u062a.<\/p>\n<p>\u0627\u06cc\u0646 \u0645\u0646\u062c\u0631 \u0628\u0647 <em>\u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u0632\u0645\u0627\u0646\u06cc<\/em> \u0627\u0632 \u0648\u062c\u0648\u062f \u0627\u06cc\u0646 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 <code>O(|E|+|V|log|V|)<\/code>.<\/p>\n<\/div>\n<p><script>\n                        !function(f,b,e,v,n,t,s)\n                        {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n                        n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n                        if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n                        n.queue=();t=b.createElement(e);t.async=!0;\n                        t.src=v;s=b.getElementsByTagName(e)(0);\n                        s.parentNode.insertBefore(t,s)}(window, document,'script',\n                        'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n                        fbq('init', '525232124909042');\n                        fbq('track', 'PageView');\n                    <\/script><br \/>\n<br \/><br \/>\n<br \/>\u0645\u0646\u062a\u0634\u0631 \u0634\u062f\u0647 \u062f\u0631 1403-01-08 20:36:07<br \/>\n<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;15116&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;\u0627\u0645\u062a\u06cc\u0627\u0632 \u0634\u0645\u0627 \u0628\u0647 \u0627\u06cc\u0646 \u0645\u0637\u0644\u0628&quot;,&quot;legend&quot;:&quot;0\\\/5 (0 \u0631\u0627\u06cc)&quot;,&quot;size&quot;:&quot;30&quot;,&quot;title&quot;:&quot;\u0646\u0645\u0648\u062f\u0627\u0631\u0647\u0627 \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646 - \u062a\u0626\u0648\u0631\u06cc \u0648 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} ({count} \u0631\u0627\u06cc)&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 24px;\">\n            <span class=\"kksr-muted\">\u0627\u0645\u062a\u06cc\u0627\u0632 \u0634\u0645\u0627 \u0628\u0647 \u0627\u06cc\u0646 \u0645\u0637\u0644\u0628<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">\u0632\u0645\u0627\u0646 \u0644\u0627\u0632\u0645 \u0628\u0631\u0627\u06cc \u0645\u0637\u0627\u0644\u0639\u0647: <\/span> <span class=\"rt-time\"> 7<\/span> <span class=\"rt-label rt-postfix\">\u062f\u0642\u06cc\u0642\u0647<\/span><\/span>\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062f\u0627\u06cc\u06a9\u0633\u062a\u0631\u0627 \u0637\u0631\u0627\u062d\u06cc \u0634\u062f\u0647 \u0628\u0631\u0627\u06cc \u06cc\u0627\u0641\u062a\u0646 \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631\u0647\u0627\u06cc \u0628\u06cc\u0646 \u06af\u0631\u0647 \u0647\u0627 \u062f\u0631 \u06cc\u06a9 \u0646\u0645\u0648\u062f\u0627\u0631. \u0627\u06cc\u0646 \u062a\u0648\u0633\u0637 \u06cc\u06a9 \u062f\u0627\u0646\u0634\u0645\u0646\u062f \u06a9\u0627\u0645\u067e\u06cc\u0648\u062a\u0631 \u0647\u0644\u0646\u062f\u06cc\u060c Edsger Wybe Dijkstra\u060c \u062f\u0631 \u0633\u0627\u0644 1956\u060c \u0632\u0645\u0627\u0646\u06cc \u06a9\u0647 \u062f\u0631 \u062d\u0627\u0644 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0648\u062a\u0627\u0647 \u062a\u0631\u06cc\u0646 \u0645\u0633\u06cc\u0631 \u0627\u0632 \u0631\u0648\u062a\u0631\u062f\u0627\u0645 \u0628\u0647 \u06af\u0631\u0648\u0646\u06cc\u0646\u06af\u0646 \u0628\u0648\u062f\u060c \u0637\u0631\u0627\u062d\u06cc \u0634\u062f. \u0633\u0647 \u0633\u0627\u0644 \u0628\u0639\u062f \u0645\u0646\u062a\u0634\u0631 \u0634\u062f. \u062a\u0648\u062c\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f: \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Dijkstra \u062f\u0631 \u0637\u0648\u0644 \u0633\u0627\u0644\u0647\u0627 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":15117,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1743,620],"tags":[1748,1747,1754,1744,3420,3483,2750,1805,3482,1745],"class_list":["post-15116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-programming","tag-python-hosting","tag-python-vps","tag-1754","tag-1744","tag-3420","tag-3483","tag-2750","tag-1805","tag-3482","tag-1745"],"acf":[],"_links":{"self":[{"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/posts\/15116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/comments?post=15116"}],"version-history":[{"count":0,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/posts\/15116\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/media\/15117"}],"wp:attachment":[{"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/media?parent=15116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/categories?post=15116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rasanegaar.com\/blog\/wp-json\/wp\/v2\/tags?post=15116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}