{"id":375470,"date":"2024-05-21T06:25:21","date_gmt":"2024-05-21T06:25:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375470"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375470","title":{"rendered":"<span>\u0412\u0435\u043a \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b04\/14a\/c19\/b0414ac194ac323f3de6cbfa37cad530.png\" alt=\"\u041e\u0447\u0435\u043d\u044c \u0442\u043e\u0440\u043e\u043f\u044f\u0449\u0438\u0435\u0441\u044f \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 \u0410 \u0432 \u043f\u0443\u043d\u043a\u0442 \u0411\" title=\"\u041e\u0447\u0435\u043d\u044c \u0442\u043e\u0440\u043e\u043f\u044f\u0449\u0438\u0435\u0441\u044f \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 \u0410 \u0432 \u043f\u0443\u043d\u043a\u0442 \u0411\" width=\"2476\" height=\"1300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b04\/14a\/c19\/b0414ac194ac323f3de6cbfa37cad530.png\"\/><\/p>\n<div><figcaption>\u041e\u0447\u0435\u043d\u044c \u0442\u043e\u0440\u043e\u043f\u044f\u0449\u0438\u0435\u0441\u044f \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 \u0410 \u0432 \u043f\u0443\u043d\u043a\u0442 \u0411<\/figcaption><\/div>\n<\/figure>\n<p>\u041b\u044e\u0434\u0438 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0441\u0432\u043e\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438. \u041f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u0440\u043e\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0438\u043c\u043f\u0435\u0440\u0438\u0438 \u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0435\u0451 \u0440\u0430\u0441\u0446\u0432\u0435\u0442\u0443, \u043d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0440\u043e\u0436\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0431\u044b\u0432\u0430\u044e\u0442 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0435 \u0438\u0437\u044a\u044f\u043d\u044b, \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043d\u0435\u0431\u0435\u0437\u044b\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%97%D0%B0%D0%B4%D0%B0%D1%87%D0%B0_%D0%BE_%D1%81%D0%B5%D0%BC%D0%B8_%D0%BA%D1%91%D0%BD%D0%B8%D0%B3%D1%81%D0%B1%D0%B5%D1%80%D0%B3%D1%81%D0%BA%D0%B8%D1%85_%D0%BC%D0%BE%D1%81%D1%82%D0%B0%D1%85\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0451\u043d\u0438\u0433\u0441\u0431\u0435\u0440\u0433\u0441\u043a\u0438\u0445 \u043c\u043e\u0441\u0442\u0430\u0445<\/a>, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0442\u0435\u043e\u0440\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u0442\u043e, \u0447\u0442\u043e \u0441 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u0442\u0430\u043b\u0438 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u0438\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0432\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0446\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0445 \u043d\u0430\u0443\u043a. <em>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438<\/em> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445, \u0437\u0432\u0443\u0447\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0440\u043e\u0433, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0443 \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u0433\u043e\u0440\u043e\u0434\u0430 \u0410 \u0432 \u0433\u043e\u0440\u043e\u0434 \u0411 \u043f\u0440\u043e\u0439\u0434\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438 \u0432 1931\u0433., \u0441\u043f\u0443\u0441\u0442\u044f 25 \u043b\u0435\u0442 \u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0443\u0432\u0430\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043d\u0430 \u0433\u0440\u0430\u0444\u0430\u0445. \u041d\u0430 \u043d\u0451\u043c \u0436\u0435, \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0441\u0442\u043d\u044b, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0438\u0431\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0433\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438\/stackoverflow \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0442\u044c, \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e.<\/p>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/553\/669\/f9a\/553669f9af6e58d6abe506d4b3afd6ea.jpg\" alt=\"\u0416\u0435\u043d\u043e \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u043a\u043e\u0432 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0412\u0435\u043d\u0433\u0435\u0440\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438-\u041a\u0451\u043d\u0438\u0433\u0430-\u041a\u0443\u043d\u0430\" title=\"\u0416\u0435\u043d\u043e \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u043a\u043e\u0432 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0412\u0435\u043d\u0433\u0435\u0440\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438-\u041a\u0451\u043d\u0438\u0433\u0430-\u041a\u0443\u043d\u0430\" width=\"440\" height=\"579\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/553\/669\/f9a\/553669f9af6e58d6abe506d4b3afd6ea.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0416\u0435\u043d\u043e \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u043a\u043e\u0432 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0412\u0435\u043d\u0433\u0435\u0440\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438-\u041a\u0451\u043d\u0438\u0433\u0430-\u041a\u0443\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430 \u0441 60\u0445 \u0433\u043e\u0434\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043f\u043e\u0447\u0442\u0438 \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442, \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0431\u044b\u043b \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0445\u043e\u0442\u044c \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441 \u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0444\u043e\u043a\u0443\u0441 \u0441\u043c\u0435\u0441\u0442\u0438\u043b\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434 \u043a\u0430\u0442 \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0430\u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u0435\u043d\u044f \u043e\u0433\u043e\u0440\u0447\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0443\u0447\u0451\u0442\u0430 \u0444\u043b\u0430\u0433\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0430 \u0432 HOMM3 \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 \u043f\u0443\u0442\u0438, \u043d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0447\u0442\u043e \u0437\u0430 \u043c\u0443\u0436\u0438\u043a\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u0440\u044f\u0434\u043e\u043c \u0441 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u043e\u0439?  <\/p>\n<h2>\u041f\u0440\u0435\u0430\u043c\u0431\u0443\u043b\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u0430\u043d \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"G=\\langle V, E\\rangle\" alt=\"G=\\langle V, E\\rangle\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6a0\/1b9\/1e0\/6a01b91e013a696b09d0469c5850883d.svg\" width=\"94\" height=\"22\"\/>, \u0433\u0434\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"V\" alt=\"V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dc4\/d21\/940\/dc4d21940496998a16eb543b07825e12.svg\" width=\"15\" height=\"17\"\/> &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/be4\/601\/1b3\/be46011b36786747ceae43c9664f089b.svg\" width=\"12\" height=\"12\"\/> , <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"E\\subset V\\times V\" alt=\"E\\subset V\\times V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f9\/ab3\/3e9\/1f9ab33e98468d36c88a7f77f604e338.svg\" width=\"94\" height=\"17\"\/> &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e96\/c9a\/f6a\/e96c9af6aa0213f2c725c4de56e3a184.svg\" width=\"17\" height=\"12\"\/> , \u043a\u0430\u0436\u0434\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u043c\u0435\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell: E\\rightarrow [0, +\\infty)\" alt=\"\\ell: E\\rightarrow [0, +\\infty)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f63\/ee2\/682\/f63ee2682cf25cfc88d6becf9545687e.svg\" width=\"134\" height=\"22\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell(u, v)\" alt=\"\\ell(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9af\/394\/277\/9af3942773da73a2afc6d5766b7b3d36.svg\" width=\"52\" height=\"22\"\/> &#8212; \u0434\u043b\u0438\u043d\u0430 \u0440\u0435\u0431\u0440\u0430 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a80\/177\/3c5\/a801773c5ddc360fdd85ed7fcee21810.svg\" width=\"11\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ee0\/8ef\/b59\/ee08efb593d3fc7f845fecd8b4a7f7af.svg\" width=\"9\" height=\"12\"\/> \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0433\u0440\u0430\u0444\u0435.<\/p>\n<p><strong>\u041f\u0443\u0442\u044c <\/strong>\u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/539\/c00\/347\/539c00347684ec08120b0e91ee99af11.svg\" width=\"9\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed9\/434\/ef6\/ed9434ef60ba2590976d193deed4a102.svg\" width=\"7\" height=\"16\"\/> &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s=v_0, v_1, \\ldots, v_k=t,\" alt=\"s=v_0, v_1, \\ldots, v_k=t,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c47\/001\/992\/c470019921244994406c737e9ad0e300.svg\" width=\"179\" height=\"19\"\/> \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0440\u0435\u0431\u0440\u043e\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(v_i, v_{i+1})\\in E\" alt=\"(v_i, v_{i+1})\\in E\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a61\/bb2\/3b7\/a61bb23b752123e507309e719ecc61af.svg\" width=\"111\" height=\"22\"\/>. <strong>\u0414\u043b\u0438\u043d\u0430<\/strong> \u043f\u0443\u0442\u0438 &#8212; \u0441\u0443\u043c\u043c\u0430 \u0434\u043b\u0438\u043d \u0440\u0435\u0431\u0451\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u0443\u0442\u0438. <strong>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438:<\/strong> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a-\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q\\subset V\\times V\" alt=\"Q\\subset V\\times V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/112\/50f\/5d4\/11250f5d45b3d8bfd263f620e5d73816.svg\" width=\"94\" height=\"20\"\/>\u043d\u0430\u0439\u0442\u0438 \u043f\u0443\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0434\u043b\u0438\u043d\u044b. \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d(u, v)\" alt=\"d(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/76e\/29b\/a93\/76e29ba935a407c8e809c88357881be3.svg\" width=\"54\" height=\"22\"\/> \u0434\u043b\u0438\u043d\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/708\/cf5\/fda\/708cf5fdada55ca8a61d07dea2ea6fb3.svg\" width=\"11\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/833\/dc8\/4ca\/833dc84ca3bb963aad01363f4355bd7d.svg\" width=\"9\" height=\"12\"\/>.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>SSSP (single source shortest path): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>APSP (all pair shortest path): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0434\u043e \u0432\u0441\u0435\u0445<\/p>\n<\/li>\n<li>\n<p>P2P (point to point): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e \u0434\u0440\u0443\u0433\u043e\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 SSSP \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c\u0443 \u043f\u0443\u0442\u0438 \u043e\u0442 \u0438\u0441\u0442\u043e\u043a\u0430 \u0434\u043e \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"prev(v)\" alt=\"prev(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/003\/fc9\/bd0\/003fc9bd0e0f7da487327aed84761b7c.svg\" width=\"62\" height=\"22\"\/> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/82c\/b7c\/4ba\/82cb7c4ba4744b8c04ad5b28c2a329ce.svg\" width=\"9\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/209\/38b\/a36\/20938ba36d87795ef572f79154856c7e.svg\" width=\"9\" height=\"12\"\/> , \u0442\u043e \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\{prev(v)~|~v\\neq s\\}\\subset E\" alt=\"\\{prev(v)~|~v\\neq s\\}\\subset E\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/345\/74a\/7e6\/34574a7e6162a69876e6cea9f320cca9.svg\" width=\"180\" height=\"22\"\/> \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 <strong>\u0434\u0435\u0440\u0435\u0432\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 <\/strong>&#8212; \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0445\u0440\u0430\u043d\u044f \u0438\u0445 \u0432\u0441\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0430 \u0433\u0434\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\\leftarrow expression\" alt=\"u\\leftarrow expression\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/de1\/e55\/8b7\/de1e558b76a0cddf6890dd1d5ded964b.svg\" width=\"134\" height=\"19\"\/> \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7be\/602\/856\/7be602856f42cf716b1c85d17b915130.svg\" width=\"11\" height=\"12\"\/>, \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430\/\u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0443\u0433\u043b\u044b\u043c\u0438 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"dictionary(v)\" alt=\"dictionary(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/62c\/4e3\/c5f\/62c4e3c5f73e1aef7310060506719858.svg\" width=\"113\" height=\"22\"\/>\u0432\u043c\u0435\u0441\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"dictionary[v]\" alt=\"dictionary[v]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/792\/a0c\/0e0\/792a0c0e04c8a9290b3054e39706f232.svg\" width=\"108\" height=\"22\"\/>, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python, \u0434\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u041e\u041e\u041f \u0433\u0440\u0430\u0444 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 <\/p>\n<pre><code>Dict[int, Dict[int, float]]<\/code><\/pre>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>graph[u][v]<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u0438\u043d\u0435<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell(u, v)\" alt=\"\\ell(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/96f\/302\/350\/96f302350e7a9330768875d6b84e7c70.svg\" width=\"52\" height=\"22\"\/>.<\/p>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0431\u0443\u0434\u0443\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 OSM (\u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0432 \u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433\u0435 \u0434\u043e\u0439\u0442\u0438 \u043e\u0442 \u0412\u043b\u0430\u0434\u0438\u043c\u0438\u0440\u0441\u043a\u043e\u0439 \u0434\u043e \u042e\u0431\u0438\u043b\u0435\u0439\u043d\u043e\u0433\u043e)<\/p>\n<details class=\"spoiler\">\n<summary>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import osmnx  G = osmnx.graph_from_point((59.93893094417527, 30.32268115454809), dist=2500) s = 365356365 t = 8518165879 shortest_path = osmnx.routing.shortest_path(G, s, t, weight='length') osmnx.plot.plot_graph_route(G,                             shortest_path,                             route_color='g',                             node_size=2,                             node_color='red',                             edge_color='b',                             edge_linewidth=0.2,                             bgcolor='white')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c8a\/009\/bee\/c8a009bee391eb32f05cceb231c6dfa4.png\" alt=\"\" title=\"\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8a\/009\/bee\/c8a009bee391eb32f05cceb231c6dfa4.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b: Scanning method, \u0424\u043e\u0440\u0434-\u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u0423\u043e\u0440\u0448\u0435\u043b\u043b-\u0424\u043b\u043e\u0439\u0434, \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430<\/h2>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/22a\/f1e\/165\/22af1e165da2a8a3f84f9595c1ef5bf7.jpg\" alt=\"\u041b\u0435\u0441\u0442\u0435\u0440 \u0424\u043e\u0440\u0434 \u043c\u043b\u0430\u0434\u0448\u0438\u0439, \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438 \u0424\u043e\u0440\u0434\u0430-\u0424\u0430\u043b\u043a\u0435\u0440\u0441\u043e\u043d\u0430\" title=\"\u041b\u0435\u0441\u0442\u0435\u0440 \u0424\u043e\u0440\u0434 \u043c\u043b\u0430\u0434\u0448\u0438\u0439, \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438 \u0424\u043e\u0440\u0434\u0430-\u0424\u0430\u043b\u043a\u0435\u0440\u0441\u043e\u043d\u0430\" width=\"202\" height=\"270\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/22a\/f1e\/165\/22af1e165da2a8a3f84f9595c1ef5bf7.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u041b\u0435\u0441\u0442\u0435\u0440 \u0424\u043e\u0440\u0434 \u043c\u043b\u0430\u0434\u0448\u0438\u0439, \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438 \u0424\u043e\u0440\u0434\u0430-\u0424\u0430\u043b\u043a\u0435\u0440\u0441\u043e\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u043b\u044f SSSP \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u0424\u043e\u0440\u0434\u043e\u043c \u0432 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0445 \u043f\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c. \u0418\u0437-\u0437\u0430 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u0435\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043b\u0438\u0431\u043e <em>scanning method<\/em>, \u043b\u0438\u0431\u043e <em>labelling method <\/em>(\u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0432 \u0440\u0443\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435). \u041c\u0435\u0442\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0432\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0440\u0448\u0438\u043d: <em>\u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435,<\/em>\u0438 <em>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435, <\/em>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d7a\/ccc\/79b\/d7accc79b5ce95d7789ec10cbbc2e6cd.svg\" width=\"9\" height=\"12\"\/> \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v) \" alt=\"w(v) \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c9\/12b\/4f7\/5c912b4f71fafb13effb5c4e3163f990.svg\" width=\"38\" height=\"22\"\/> \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0443\u0442\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"prev(v)\" alt=\"prev(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af9\/a9c\/4bd\/af9a9c4bdbafd66627bf05a67841a8a3.svg\" width=\"62\" height=\"22\"\/> <em>. <\/em>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc2\/909\/a08\/bc2909a08abb356d9caf7966d110e55b.svg\" width=\"9\" height=\"12\"\/> \u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(s)=0, w(v)=+\\infty~v\\neq s\" alt=\"w(s)=0, w(v)=+\\infty~v\\neq s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ce7\/567\/7f4\/ce75677f4292ed5a8fa1884ba11c233a.svg\" width=\"229\" height=\"22\"\/>. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/p>\n<ul>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Relax(u, v)\" alt=\"Relax(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4e3\/5d3\/f8a\/4e35d3f8ac5c2720d1f7829c179b21f5.svg\" width=\"95\" height=\"22\"\/>: \u0435\u0441\u043b\u0438 <img class=\"formula inline\" source=\"w(v)>w(u)+\\ell(u, v)&#187; alt=&#187;w(v)>w(u)+\\ell(u, v)&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/831\/513\/12b\/83151312bc0fd6bddd53b2ade06cf544.svg&#187; width=&#187;179&#8243; height=&#187;22&#8243;\/> \u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\\leftarrow w(u)+\\ell(u, v);~~prev(v)\\leftarrow u\" alt=\"w(v)\\leftarrow w(u)+\\ell(u, v);~~prev(v)\\leftarrow u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e0a\/829\/d32\/e0a829d323bf5f8bdfb513418736b96e.svg\" width=\"304\" height=\"22\"\/>\u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dae\/fed\/0d9\/daefed0d9470bad104419201e54149ef.svg\" width=\"9\" height=\"12\"\/>\u0432 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Scan(u)\" alt=\"Scan(u)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/207\/0f5\/b50\/2070f5b505f312e642342da851683655.svg\" width=\"69\" height=\"22\"\/>: \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Relax(u, v)\" alt=\"Relax(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/90c\/d7a\/23f\/90cd7a23f92ec3776c13df71b1194523.svg\" width=\"95\" height=\"22\"\/> \u0434\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(u, v)\\in E\" alt=\"(u, v)\\in E\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/100\/2ac\/8c8\/1002ac8c8943b791a77309754b66b035.svg\" width=\"82\" height=\"22\"\/> \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/815\/03a\/a83\/81503aa8330985bdf5ec8522d2f2182b.svg\" width=\"11\" height=\"12\"\/>\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b: <\/strong>\u043f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0451<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 scanning method<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from collections import Counter  def relax(graph: Dict[int, Dict[int, float]],           u: int,           v: int,           distances: Dict[int, float],           prev: Dict[int, int],           labelled: Set,           stats: Counter = None):     if stats is not None:         stats[\"relax_calls\"] += 1     if v not in distances or distances[v] > distances[u] + graph[u][v]:         if stats is not None:             stats[\"distance_updates\"] += 1         distances[v] = distances[u] + graph[u][v]         prev[v] = u         labelled.add(v)  def scan(graph: Dict[int, Dict[int, float]],          node: int,          distances: Dict[int, float],          prev: Dict[int, int],          labelled: Set,          stats: Counter = None):     if stats is not None:         stats[\"scan_calls\"] += 1              for other, length in graph[node].items():         relax(graph, node, other, distances, prev, labelled, stats)     # labelled.remove(node)  def scanning_method(graph: Dict[int, Dict[int, float]],                     source: int,                     target: int = None,                     stats: Counter = None):     distances = {source: 0}     prev = dict()     labelled = {source}     while len(labelled) > 0:         u = labelled.pop()         if u == target:             break         scan(graph, u, distances, prev, labelled, stats)      return distances, prev<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0441\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u0435\u0440\u0448\u0438\u043d \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043d\u044b\u043c\u0438 \u0441\u043b\u0443\u0447\u0430\u044f\u043c\u0438 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 scanning method<\/summary>\n<div class=\"spoiler__content\">\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e25\/ee7\/157\/e25ee715792513bbbd1e080643cd6842.svg\" width=\"14\" height=\"12\"\/> \u043d\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0445\u043e\u0434\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)&lt;+\\infty\" alt=\"w(v)&lt;+\\infty\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/661\/83f\/416\/66183f416a34233ec201c02161b1b7ba.svg\" width=\"98\" height=\"22\"\/> , \u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0443\u0442\u044c \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5af\/5f9\/366\/5af5f9366d60c0c5da1ccb5396400f34.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/84b\/8d1\/b64\/84b8d1b64e565335072e324663436273.svg\" width=\"9\" height=\"12\"\/> \u0441 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\" alt=\"w(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ce3\/4cc\/19f\/ce34cc19f7ce280df38a372162cff532.svg\" width=\"38\" height=\"22\"\/>. \u041f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u043d\u0435\u043c \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/strong>: \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f69\/19f\/f7f\/f6919ff7fb93f6e2de45a6b276fe01c7.svg\" width=\"9\" height=\"12\"\/> \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u043d\u0435\u0451 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0443\u0442\u0435\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0442\u043e \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ec3\/02a\/ea0\/ec302aea02c7c90e18d27754b7c951dd.svg\" width=\"11\" height=\"12\"\/> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445, \u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\\leq w(u)+\\ell(u,v)\" alt=\"w(v)\\leq w(u)+\\ell(u,v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/897\/c65\/ab4\/897c65ab439e13fc58ed2ee419be04a3.svg\" width=\"179\" height=\"22\"\/>\u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/27a\/87d\/057\/27a87d0571872e3ba04239fc02454be2.svg\" width=\"9\" height=\"12\"\/>\u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d06\/d72\/76f\/d06d7276ff0a23cb4e3cef55fcddb938.svg\" width=\"11\" height=\"12\"\/> \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c, \u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\" alt=\"w(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bbb\/78b\/fa7\/bbb78bfa77133924396e5e204e8b6e46.svg\" width=\"38\" height=\"22\"\/>\u043c\u043e\u0433\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\\neq s\" alt=\"v\\neq s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/003\/5b2\/3a0\/0035b23a03f941608b57667c3bb7abc6.svg\" width=\"44\" height=\"21\"\/> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\\geq w(prev(v))+\\ell(prev(v), v)\" alt=\"w(v)\\geq w(prev(v))+\\ell(prev(v), v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7bd\/22a\/d01\/7bd22ad01bbbe944d7e3a67f2da842f5.svg\" width=\"279\" height=\"22\"\/>\u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\" alt=\"w(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a74\/504\/eb1\/a74504eb1b9d34e92325ff4f2bbf0008.svg\" width=\"38\" height=\"22\"\/> \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"prev(v)\" alt=\"prev(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f06\/257\/c80\/f06257c80c7c01a8bdbe597d9254676d.svg\" width=\"62\" height=\"22\"\/> \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e, \u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(prev(v))\" alt=\"w(prev(v))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ab\/a1f\/c39\/0aba1fc3913104a72e85536c28fd18b3.svg\" width=\"90\" height=\"22\"\/> \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c<\/strong>: \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0422\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0430\u0440\u0430 \u0432\u0435\u0440\u0448\u0438\u043d<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v, u\" alt=\"v, u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/678\/7d9\/de4\/6787d9de4e958804ff95a75fe3aab8ad.svg\" width=\"29\" height=\"15\"\/>, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435, \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 (\u0432\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0439\u0442\u0438\u0441\u044c \u0438\u0431\u043e \u0434\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ab\/0b1\/069\/7ab0b1069cad5e367cb644f141b23a13.svg\" width=\"9\" height=\"12\"\/> \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e) \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf9\/48d\/4ee\/cf948d4ee661685113af52d9dbf7b69b.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47d\/a62\/b6b\/47da62b6b08f3db31e90b38cc0de5b08.svg\" width=\"9\" height=\"12\"\/> \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a49\/5da\/422\/a495da422a3484acbeed35d7e273db6c.svg\" width=\"11\" height=\"12\"\/>. \u0422\u043e\u0433\u0434\u0430 <img class=\"formula inline\" source=\"w(v)>w(u)+\\ell(u, v)&#187; alt=&#187;w(v)>w(u)+\\ell(u, v)&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e0e\/2b2\/420\/e0e2b2420fe884506e3340a20fc247fb.svg&#187; width=&#187;179&#8243; height=&#187;22&#8243;\/> \u0447\u0442\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u043f\u0443\u043d\u043a\u0442\u0443 4 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/8b2\/396\/ad5\/8b2396ad552c83cef396fa79d5d0ef9e.jpeg\" alt=\"\u0420\u0438\u0447\u0430\u0440\u0434 \u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u043e\u0442\u0435\u0446 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\" title=\"\u0420\u0438\u0447\u0430\u0440\u0434 \u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u043e\u0442\u0435\u0446 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\" width=\"402\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8b2\/396\/ad5\/8b2396ad552c83cef396fa79d5d0ef9e.jpeg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0447\u0430\u0440\u0434 \u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u043e\u0442\u0435\u0446 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 &#8212; \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u0447\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e, \u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u0412\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u043a\u0430\u043a \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0442\u0430\u043a \u0438 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 <strong>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 <\/strong>&#8212; \u043e\u0431\u0449\u0435\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0440\u044f\u0434\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0420\u0438\u0447\u0430\u0440\u0434\u043e\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u043e\u043c. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 &#8212; \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043e\u043d \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0434\u0438\u0439. \u041d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47d\/5b8\/0e7\/47d5b80e7d322b0acda0e79f9bb1193e.svg\" width=\"10\" height=\"17\"\/> \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0430 \u043f\u0443\u0442\u044f\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e9f\/384\/66b\/e9f38466ba3ed4ba7053b3bfd4a1f34b.svg\" width=\"10\" height=\"17\"\/> \u0440\u0451\u0431\u0435\u0440. \u0415\u0441\u043b\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(u, v)\" alt=\"d_k(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/314\/215\/b24\/314215b241ff16f4759871bfd51d7e6e.svg\" width=\"63\" height=\"22\"\/> \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24b\/ff5\/633\/24bff56338d5e42d1c86a8bfc0cfe88a.svg\" width=\"11\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fdd\/b13\/eca\/fddb13eca2e901b6453ce62be107eac6.svg\" width=\"9\" height=\"12\"\/> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/799\/38a\/b24\/79938ab245097eba2ca250ca120452b8.svg\" width=\"10\" height=\"17\"\/> \u0448\u0430\u0433\u043e\u0432, \u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(v, v)=0,~d_0(u, v)=\\infty\" alt=\"d_k(v, v)=0,~d_0(u, v)=\\infty\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fbb\/95a\/45f\/fbb95a45fc558d604b9186b579dbf7c0.svg\" width=\"218\" height=\"22\"\/> \u043f\u0440\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\\neq v\" alt=\"u\\neq v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/221\/988\/b97\/221988b97dc08bddfc2631c71b3e58ac.svg\" width=\"46\" height=\"21\"\/> \u0438, \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(s, v)=\\min\\{\\min_u d_{k-1}(s, u)+\\ell(u, v), d_{k-1}(s, v)\\}\" alt=\"d_k(s, v)=\\min\\{\\min_u d_{k-1}(s, u)+\\ell(u, v), d_{k-1}(s, v)\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c86\/8b9\/9b6\/c868b99b6feb3812f347fff9522dcead.svg\" width=\"416\" height=\"31\"\/>. \u0421\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 (\u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0435) \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d\" alt=\"d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb0\/bdb\/1f0\/cb0bdb1f0fc8eb59049dee7255058ef0.svg\" width=\"10\" height=\"17\"\/> \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043c\u0430\u043b\u044b\u0445 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b2c\/566\/384\/b2c566384aee58de0f27405c64584b71.svg\" width=\"10\" height=\"17\"\/>, \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0434\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(m)\" alt=\"\\mathcal{O}(m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd7\/baf\/dd4\/cd7bafdd4e886e5e9f45cdbd75a71a37.svg\" width=\"47\" height=\"22\"\/>, \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0434\u0438\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n-1\" alt=\"n-1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/feb\/b1b\/107\/febb1b1077f8e8cd589e90c256fac8d2.svg\" width=\"45\" height=\"17\"\/>, \u0447\u0442\u043e \u0434\u0430\u0451\u0442 \u043e\u0446\u0435\u043d\u043a\u0443  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 &#8212; \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f  <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c37\/ed8\/2f2\/c37ed82f23cba5fd28028299daa9729b.svg\" width=\"10\" height=\"17\"\/> \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0434\u043b\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k-1,\" alt=\"k-1,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd6\/539\/fd3\/dd6539fd3586462e88edc15a5bac9a7f.svg\" width=\"49\" height=\"20\"\/> \u0442\u0430\u043a \u0435\u0449\u0435 \u0438 \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0430\u0434\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def bellman_ford_moore(graph: Dict[int, Dict[int, float]],                        source: int) -> Tuple[Dict[int, float], Dict[int, int]]:     distances = {source: 0}     prev = dict()     changed = True     for k in graph:         if not changed:             break         changed = False         for u, adjacent in graph.items():             if u not in distances:                 continue             for v, l in adjacent.items():                 if v not in distances or distances[v] > distances[u] + l:                     distances[v] = distances[u] + l                     prev[v] = u                     changed = True      return distances, prev<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0437\u0434\u043d\u0435\u0435 \u041c\u0443\u0440 \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0432 \u0435\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 scanning method \u0441 FIFO \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0440\u0448\u0438\u043d (\u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 shortest path faster algorithm SPFA , \u0432 \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a BFM \u043e\u0442 Bellman-Ford-Moore). <\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/8c6\/fb0\/e8e\/8c6fb0e8ef920efc6d7f80024cd3496b.jpg\" alt=\"\u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430, \u0430\u0432\u0442\u043e\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f SSSP\" title=\"\u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430, \u0430\u0432\u0442\u043e\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f SSSP\" width=\"1200\" height=\"1600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c6\/fb0\/e8e\/8c6fb0e8ef920efc6d7f80024cd3496b.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430, \u0430\u0432\u0442\u043e\u0440 \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f SSSP<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438\u0434\u0435\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u043b\u0438 \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435, \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0432\u0430: \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0434\u043b\u044f SSSP \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u043b\u043e\u0439\u0434\u0430-\u0423\u043e\u0440\u0448\u0435\u043b\u043b\u0430 \u0434\u043b\u044f APSP. \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0433\u0440\u0430\u0444\u0430 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0442<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f22\/661\/235\/f226612352c8a201c672b12940d27612.svg\" width=\"9\" height=\"12\"\/>, \u0442.\u0435. \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s=v_1, v_2, \\ldots, v_n\" alt=\"s=v_1, v_2, \\ldots, v_n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ab\/31f\/0cc\/8ab31f0cc98343de04fc396609d0ac50.svg\" width=\"142\" height=\"15\"\/> \u0442\u0430\u043a\u043e\u0432\u0430, \u0447\u0442\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d(s, v_i)\\leq d(s, v_{i+1})\" alt=\"d(s, v_i)\\leq d(s, v_{i+1})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e9b\/2dd\/fde\/e9b2ddfde1b5e9e2feaa6490cba24b90.svg\" width=\"161\" height=\"22\"\/>, \u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0440\u0451\u0431\u0435\u0440 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/998\/65d\/fb2\/99865dfb23947be43e0b08775f681a3e.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v_i\" alt=\"v_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/46b\/ac6\/368\/46bac6368bf1e8ca4ac4f503fa5a96a0.svg\" width=\"16\" height=\"15\"\/> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v_1, v_2, \\ldots, v_i\" alt=\"v_1, v_2, \\ldots, v_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c18\/fd4\/499\/c18fd44995375cc627ce5467ffe77209.svg\" width=\"104\" height=\"15\"\/>. \u0415\u0441\u043b\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(v)\" alt=\"d_k(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d5\/dfc\/088\/4d5dfc0886b0a22d4d11df5884853599.svg\" width=\"43\" height=\"22\"\/> &#8212; \u0434\u043b\u0438\u043d\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438, \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0442\u043e\u043b\u044c\u043a\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v_1, \\ldots, v_k\" alt=\"v_1, \\ldots, v_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/413\/4b9\/506\/4134b9506bb16b0e94b9bdc96759667e.svg\" width=\"79\" height=\"15\"\/>, \u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d(s, v_k)=d_{k-1}(v_k)\" alt=\"d(s, v_k)=d_{k-1}(v_k)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/293\/bfb\/dc9\/293bfbdc90371265d26485f974ba1d0c.svg\" width=\"157\" height=\"22\"\/> \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(v)=\\min\\{d_{k-1}(v), d_{k-1}(v_k)+\\ell(v_k, v)\\}\" alt=\"d_k(v)=\\min\\{d_{k-1}(v), d_{k-1}(v_k)+\\ell(v_k, v)\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb7\/0f7\/e9d\/fb70f7e9d83bf64562c81a680a93fa05.svg\" width=\"343\" height=\"22\"\/>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k\" alt=\"d_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea0\/d84\/0f7\/ea0d840f79b57eb5c277bfc19a60ed7b.svg\" width=\"19\" height=\"20\"\/> \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_{k-1}\" alt=\"d_{k-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f30\/def\/525\/f30def5251dc1dea3be0299f616ed614.svg\" width=\"36\" height=\"21\"\/> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v_k\" alt=\"v_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/da3\/d6c\/93d\/da3d6c93d4f07ce6e07ab6dd38bcd78b.svg\" width=\"18\" height=\"15\"\/> \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043d\u0430 \u0448\u0430\u0433\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k-1\" alt=\"k-1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/322\/6bf\/a13\/3226bfa13a40ac851affc4ddad034234.svg\" width=\"43\" height=\"18\"\/> \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0441 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0435\u0449\u0435 \u043d\u0435 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0433\u0430\u0445. \u0412 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u0441\u043a\u0430\u043d\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b &#8212; \u044d\u0442\u043e \u0432\u044b\u0431\u043e\u0440 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(1)\" alt=\"\\mathcal{O}(1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bcb\/86c\/0f5\/bcb86c0f52cccbd7eecae2730e80b431.svg\" width=\"40\" height=\"22\"\/> \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u044f\u0432\u043b\u044f\u043b\u0441\u044f \u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f SSSP \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u044b \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(n+m)\" alt=\"\\mathcal{O}(n+m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e88\/e13\/517\/e88e13517d381d99e9c1681cf5a8279e.svg\" width=\"82\" height=\"22\"\/>. <\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/8e1\/4ce\/393\/8e14ce3935eb1990d7ca5fb37010e450.jpg\" alt=\"\u0420\u043e\u0431\u0435\u0440\u0442 \u0422\u0430\u0440\u044c\u044f\u043d, \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0432\u044b\u0434\u0443\u043c\u0449\u0438\u043a\u043e\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u0443\u0447\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438\" title=\"\u0420\u043e\u0431\u0435\u0440\u0442 \u0422\u0430\u0440\u044c\u044f\u043d, \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0432\u044b\u0434\u0443\u043c\u0449\u0438\u043a\u043e\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u0443\u0447\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438\" width=\"1252\" height=\"1632\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8e1\/4ce\/393\/8e14ce3935eb1990d7ca5fb37010e450.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0420\u043e\u0431\u0435\u0440\u0442 \u0422\u0430\u0440\u044c\u044f\u043d, \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0432\u044b\u0434\u0443\u043c\u0449\u0438\u043a\u043e\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u0443\u0447\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u043a \u0438 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438, \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b\u0445 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 &#8212; \u0434\u0432\u043e\u0438\u0447\u043d\u0430\u044f \u043a\u0443\u0447\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}((n+m)\\log n)\" alt=\"\\mathcal{O}((n+m)\\log n)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f15\/db2\/c71\/f15db2c715f46c9d0b478b09b628ff9a.svg\" width=\"140\" height=\"22\"\/> \u0438 \u043a\u0443\u0447\u0430 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u0441 \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0437\u0430 \u0430\u043c\u043e\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0437\u0430 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(n\\log n+m)\" alt=\"\\mathcal{O}(n\\log n+m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/628\/476\/b13\/628476b130274d9bd429d3b6d10ecbeb.svg\" width=\"125\" height=\"22\"\/>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def dijkstra(graph: Dict[int, Dict[int, float]],              source: int,              target: int = None,              stats: Counter = None) -> Tuple[Dict[int, float], Dict[int, int]]:     distances = {source: 0}     prev = dict()     labelled = {source}     while len(labelled) > 0:         u = min(labelled, key=lambda x: distances[x])         labelled.remove(u)         if u == target:             break         scan(graph, u, distances, prev, labelled, stats)      return distances, prev<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/338\/b9c\/b15\/338b9cb1558af6334be3bb8623bfe138.png\" alt=\"\u0420\u043e\u0431\u0435\u0440\u0442 \u0424\u043b\u043e\u0439\u0434, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f APSP \" title=\"\u0420\u043e\u0431\u0435\u0440\u0442 \u0424\u043b\u043e\u0439\u0434, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f APSP \" width=\"270\" height=\"270\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/338\/b9c\/b15\/338b9cb1558af6334be3bb8623bfe138.png\"\/><\/p>\n<div><figcaption>\u0420\u043e\u0431\u0435\u0440\u0442 \u0424\u043b\u043e\u0439\u0434, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f APSP <\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u043b\u043e\u0439\u0434\u0430-\u0423\u043e\u0440\u0448\u0435\u043b\u043b\u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"1, \\ldots, n\" alt=\"1, \\ldots, n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/177\/00b\/2ba\/17700b2badaee134eeee7ff44a91bafe.svg\" width=\"64\" height=\"19\"\/> \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(u, v)\" alt=\"d_k(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a63\/2e1\/f68\/a632e1f68a5eee99929bfb1bd5d03bf2.svg\" width=\"63\" height=\"22\"\/> &#8212; \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u\" alt=\"u\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b18\/f1f\/590\/b18f1f590c02126266c9b2a777187e08.svg\" width=\"11\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0da\/ee8\/b8f\/0daee8b8f2a67144e5d7598e2feaf737.svg\" width=\"9\" height=\"12\"\/>, \u0438\u043c\u0435\u044e\u0449\u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b85\/215\/2b0\/b852152b0e15741bea51d19f6b81c63d.svg\" width=\"10\" height=\"17\"\/>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_0(u,v)=\\ell(u,v)\" alt=\"d_0(u,v)=\\ell(u,v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/538\/83a\/95d\/53883a95d7a46b394cfd183f70a5ca51.svg\" width=\"140\" height=\"22\"\/> \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_k(u,v)=\\min \\{d_{k-1}(u,v),d_{k-1}(u, k)+d_{k-1}(k, v)\\}\" alt=\"d_k(u,v)=\\min \\{d_{k-1}(u,v),d_{k-1}(u, k)+d_{k-1}(k, v)\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/054\/2f0\/e39\/0542f0e39ebc3650ebaa2698412d4758.svg\" width=\"413\" height=\"22\"\/> .<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/787\/4cf\/cfe\/7874cfcfee936f4be141d4138379dee6.png\" alt=\"\u0421\u043b\u0435\u0432\u0430 \u0414\u0436\u043e\u0440\u0434\u0436 \u0414\u0430\u043d\u0446\u0438\u0433, \u0431\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u043b \u0434\u0432\u0435 \u043d\u0435\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435, \u0434\u0443\u043c\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0414\u0417, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441-\u043c\u0435\u0442\u043e\u0434 \u0438 ... \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b. \u0421\u043f\u0440\u0430\u0432\u0430 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440 \u041c\u0430\u0434\u0440\u0438, \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c IPM \u0434\u043b\u044f APSP.\" title=\"\u0421\u043b\u0435\u0432\u0430 \u0414\u0436\u043e\u0440\u0434\u0436 \u0414\u0430\u043d\u0446\u0438\u0433, \u0431\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u043b \u0434\u0432\u0435 \u043d\u0435\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435, \u0434\u0443\u043c\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0414\u0417, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441-\u043c\u0435\u0442\u043e\u0434 \u0438 ... \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b. \u0421\u043f\u0440\u0430\u0432\u0430 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440 \u041c\u0430\u0434\u0440\u0438, \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c IPM \u0434\u043b\u044f APSP.\" width=\"619\" height=\"374\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/787\/4cf\/cfe\/7874cfcfee936f4be141d4138379dee6.png\"\/><\/p>\n<div><figcaption>\u0421\u043b\u0435\u0432\u0430 \u0414\u0436\u043e\u0440\u0434\u0436 \u0414\u0430\u043d\u0446\u0438\u0433, \u0431\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u043b \u0434\u0432\u0435 \u043d\u0435\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435, \u0434\u0443\u043c\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0414\u0417, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441-\u043c\u0435\u0442\u043e\u0434 \u0438 &#8230; \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b. \u0421\u043f\u0440\u0430\u0432\u0430 \u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440 \u041c\u0430\u0434\u0440\u0438, \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c IPM \u0434\u043b\u044f APSP.<\/figcaption><\/div>\n<\/figure>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u0441\u0438\u043c\u043f\u043b\u0435\u043a\u0441 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0431\u044b\u043b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043a\u0430\u043a \u043f\u043e\u0438\u0441\u043a \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0431\u044b\u043b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u043c \u0438 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u044b\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435\u0433\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 70\u0445-80\u0445 \u0433\u043e\u0434\u0430\u0445 \u041d\u0435\u0441\u0442\u0435\u0440\u043e\u0432\u044b\u043c \u0438 \u041d\u0435\u043c\u0438\u0440\u043e\u0432\u0441\u043a\u0438\u043c \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d  \u043c\u0435\u0442\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 (interior point method, IPM), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0431\u044b\u0441\u0442\u0440 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0438 \u043f\u0440\u0438 \u0438\u043c\u0435\u043b \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u0437\u0434\u043d\u0435\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u043b \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0445. \u0421\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0440\u044f\u0434 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438, \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f APSP.<\/p>\n<p>\u042d\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u0441\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u043c\u044b \u0435\u0451 \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u043e \u043f\u0430\u0440\u0443 \u0432\u0435\u0449\u0435\u0439 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0435\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"B\" alt=\"B\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb4\/c13\/6bb\/cb4c136bbff0993eb7a147cdbf4fd54b.svg\" width=\"15\" height=\"17\"\/> &#8212; \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0430, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\chi^{st}\\in \\mathbb{R}^n\" alt=\"\\chi^{st}\\in \\mathbb{R}^n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f1c\/e1c\/ce8\/f1ce1cce89c99b58570c45d107e927aa.svg\" width=\"73\" height=\"23\"\/> &#8212; \u0432\u0435\u043a\u0442\u043e\u0440 \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\chi^{st}_t=-\\chi^{st}_s=1,~\\chi^{st}_i=0,i\\neq s, t\" alt=\"\\chi^{st}_t=-\\chi^{st}_s=1,~\\chi^{st}_i=0,i\\neq s, t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3f7\/a26\/e54\/3f7a26e5452511bf514fbad0083a6d10.svg\" width=\"266\" height=\"25\"\/> , \u0442\u043e P2P \u0437\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/808\/920\/325\/80892032532ed05be19e89ece32590b7.svg\" width=\"9\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ab\/491\/fb4\/8ab491fb40a4f58478877697c187297c.svg\" width=\"7\" height=\"16\"\/> \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{array}{rl} \\mbox{\u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c} &amp; \\ell^T x\\\\\\ \\mbox{\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438} &amp; Bx=\\chi^{st} \\\\ &amp; x\\geq 0\\end{array}\" alt=\"\\begin{array}{rl} \\mbox{\u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c} &amp; \\ell^T x\\\\\\ \\mbox{\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438} &amp; Bx=\\chi^{st} \\\\ &amp; x\\geq 0\\end{array}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/521\/bf7\/fb7\/521bf7fb78fd7749c0830e390ac86d69.svg\" width=\"227\" height=\"77\"\/><\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f: \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/80d\/ecd\/b4d\/80decdb4defba35c3ea25b0791eee003.svg\" width=\"9\" height=\"12\"\/> \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1fb\/e56\/1f7\/1fbe561f73d325f486efc79216feb321.svg\" width=\"7\" height=\"16\"\/>, \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043f\u043e\u0442\u043e\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(u, v)\" alt=\"(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0e1\/893\/d80\/0e1893d80155feedc8f1eac2533a44d1.svg\" width=\"44\" height=\"22\"\/> \u0441\u0442\u043e\u0438\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell(u, v)\" alt=\"\\ell(u, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/831\/b7c\/b06\/831b7cb066f52424e52418d91598699b.svg\" width=\"52\" height=\"22\"\/>, \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; \u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u043f\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c\u0443 \u043f\u0443\u0442\u0438. \u0414\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"        \\begin{array}{rl}             \\mbox{\u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c} &amp; \\pi_s-\\pi_t, \\\\             \\mbox{\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438} &amp; \\pi_u-\\pi_v\\leq \\ell(u,v),~(u,v)\\in E.         \\end{array}\" alt=\"        \\begin{array}{rl}             \\mbox{\u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c} &amp; \\pi_s-\\pi_t, \\\\             \\mbox{\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438} &amp; \\pi_u-\\pi_v\\leq \\ell(u,v),~(u,v)\\in E.         \\end{array}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7e3\/25e\/c12\/7e325ec12fe4ad117c42edfad406ab0c.svg\" width=\"399\" height=\"50\"\/><\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f: \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u0448 \u0433\u0440\u0430\u0444 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0448\u0430\u0440\u0438\u043a\u043e\u0432 (\u0432\u0435\u0440\u0448\u0438\u043d\u044b), \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043d\u0438\u0442\u043a\u0430\u043c\u0438 (\u0440\u0451\u0431\u0440\u0430) \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0434\u043b\u0438\u043d\u044b. \u0415\u0441\u043b\u0438 \u043f\u043e\u0442\u044f\u043d\u0443\u0442\u044c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/71a\/c30\/6e1\/71ac306e1d3a91fea896372d92e26ead.svg\" width=\"9\" height=\"12\"\/> \u0432\u043b\u0435\u0432\u043e, \u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c63\/d64\/d54\/c63d64d5493d01939a7862c395f5d859.svg\" width=\"7\" height=\"16\"\/> \u0432\u043f\u0440\u0430\u0432\u043e, \u043d\u0430 \u043a\u0430\u043a\u043e\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0430\u0441\u0442\u044f\u043d\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f? \u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/688\/c3c\/b7e\/688c3cb7e5ec7cebf6bd254e3e92cf4a.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/666\/df1\/5f1\/666df15f1f1153c834221adc7dc71a0d.svg\" width=\"7\" height=\"16\"\/>. \u0412\u0435\u043b\u0438\u0447\u0438\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1b5\/f98\/56a\/1b5f9856abe7b1dd72d3c0e32fb9903c.svg\" width=\"11\" height=\"12\"\/>, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c \u0432 \u0434\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <strong>\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438<\/strong> \u0438 \u0438\u0433\u0440\u0430\u044e\u0442 \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u0442\u0440\u044e\u043a \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u0438\u043d\u044b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\ell_\\pi(u, v)=\\ell(u, v)-\\pi(u)+\\pi(v)\" alt=\"\\ell_\\pi(u, v)=\\ell(u, v)-\\pi(u)+\\pi(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/871\/244\/592\/87124459258b24b14a5f2e535aa6f809.svg\" width=\"259\" height=\"22\"\/><\/p>\n<p>\u0414\u043b\u0438\u043d\u0430 \u043f\u0443\u0442\u0438 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043d\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{array}{rl}                  \\ell_\\pi(P)&amp;=\\sum_{i=1}^n\\ell_\\pi(v_i, v_{i+1}) \\\\         &amp;=\\sum_{i=1}^n[\\ell(v_i, v_{i+1})-\\pi(v_{i+1})+\\pi(v_i)]\\\\         &amp;=\\ell(P)-\\pi(v_0)+\\pi(v_{n+1})          \\end{array}\" alt=\"\\begin{array}{rl}                  \\ell_\\pi(P)&amp;=\\sum_{i=1}^n\\ell_\\pi(v_i, v_{i+1}) \\\\         &amp;=\\sum_{i=1}^n[\\ell(v_i, v_{i+1})-\\pi(v_{i+1})+\\pi(v_i)]\\\\         &amp;=\\ell(P)-\\pi(v_0)+\\pi(v_{n+1})          \\end{array}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa8\/c95\/d1e\/aa8c95d1eb00554f4b8d2828a55eb938.svg\" width=\"378\" height=\"81\"\/><\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0443\u0442\u0438, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043f\u0430\u0440\u0443 \u0432\u0435\u0440\u0448\u0438\u043d, \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443, \u0438\u0437 \u0447\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f7f\/59e\/686\/f7f59e686fafa8e58497140ab83ed8e9.svg\" width=\"8\" height=\"17\"\/> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u043c \u043f\u0443\u0442\u0451\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell_\\pi\" alt=\"\\ell_\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f56\/776\/bc6\/f56776bc69e3eac85cf294402d57528b.svg\" width=\"18\" height=\"20\"\/>. \u0422\u0430\u043a\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <strong>\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c\u0438.<\/strong> \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u043a\u0442: \u0435\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e7c\/bcc\/320\/e7cbcc320000254e5f5f720e8a69c8f4.svg\" width=\"11\" height=\"12\"\/> &#8212; \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/231\/590\/e00\/231590e00d71c2999e30a1a7459db37f.svg\" width=\"8\" height=\"17\"\/>, \u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0434\u043b\u0438\u043d\u044b \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 (\u0442\u0430\u043a \u043a\u0430\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435). \u041d\u0430 \u044d\u0442\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0436\u043e\u043d\u0441\u043e\u043d\u0430 \u0434\u043b\u044f APSP: \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0432\u0435\u0440\u0448\u0438\u043d, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0434\u043b\u0438\u043d\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u042d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u0443 \u0423\u043e\u0440\u0448\u0435\u043b\u043b\u0430-\u0424\u043b\u043e\u0439\u0434\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m&lt;&lt;n^2\" alt=\"m&lt;&lt;n^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13e\/ee1\/02b\/13eee102b9b7612a26d9dad2235deb05.svg\" width=\"78\" height=\"21\"\/>.<\/p>\n<h2>\u0423\u0441\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u0438 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0434\u043b\u044f P2P <\/h2>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u0446\u0435\u043d\u043a\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0441 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0443\u043b\u0443\u0447\u0448\u0430\u0435\u043c\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(m)\" alt=\"\\mathcal{O}(m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf8\/22f\/6d1\/cf822f6d10d3e5049c7e4a7276895e07.svg\" width=\"47\" height=\"22\"\/>\u0434\u043b\u044f SSSP, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 P2P \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444 \u0446\u0435\u043b\u0438\u043a\u043e\u043c: \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32a\/e16\/ccf\/32ae16ccf63ed468562049e8d589c93b.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c46\/03a\/b88\/c4603ab882e21e0c1aa5ff8ddca029f7.svg\" width=\"7\" height=\"16\"\/>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0435\u0441\u043b\u0438 \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/324\/cee\/0fd\/324cee0fd3a28767548e3f6c907786b4.svg\" width=\"7\" height=\"16\"\/>.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def graph_from_osmnx(G):     graph = dict()     for n, adj in G.adjacency():         if n not in graph:             graph[n] = dict()         for e, eattr in adj.items():             for _, iattr in eattr.items():                 if e not in graph[n] or graph[n][e] > iattr[\"length\"]:                     graph[n][e] = iattr[\"length\"]     return graph  g = graph_from_osmnx(G) distances, prev = dijkstra(g, s, t)  def print_route_and_visited(graph, source, target, distances, prev):     route = [target]     cur = target     while cur != source:         cur = prev[cur]         route.append(cur)     return osmnx.plot.plot_graph_route(G.subgraph(list(distances.keys())), list(reversed(route)), route_color='g', node_size=2, node_color='r', edge_color='b', edge_linewidth=0.2, bgcolor='white', close=True);  print_route_and_visited(G, s, t, distances, prev)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/305\/f40\/4c6\/305f404c6a70ca6b96009435239c28f1.png\" alt=\"\u0412\u0435\u0440\u0448\u0438\u043d\u0430, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c\" title=\"\u0412\u0435\u0440\u0448\u0438\u043d\u0430, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/305\/f40\/4c6\/305f404c6a70ca6b96009435239c28f1.png\"\/><\/p>\n<div><figcaption>\u0412\u0435\u0440\u0448\u0438\u043d\u0430, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/details>\n<p>\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b &#8212; \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 meet-in-the-middle: \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u0443\u0442\u0438 \u0441 \u0434\u0432\u0443\u0445 \u043a\u043e\u043d\u0446\u043e\u0432, \u043e\u0442<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/68f\/0dd\/0e1\/68f0dd0e136451fb70f8e52bb9907a24.svg\" width=\"9\" height=\"12\"\/> \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c  \u0433\u0440\u0430\u0444\u0435 \u0438 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f44\/f75\/d56\/f44f75d5622f1bbeb326a8042c54cf9c.svg\" width=\"7\" height=\"16\"\/> \u0432 \u0433\u0440\u0430\u0444\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044b \u0440\u0451\u0431\u0440\u0430, \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u041e\u0431\u0449\u0438\u0439 \u0441\u043c\u044b\u0441\u043b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u043d\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d\" alt=\"d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ed\/2c4\/1bb\/0ed2c41bb38413f4effef1d7a286c25d.svg\" width=\"10\" height=\"17\"\/> \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fc1\/28b\/c0e\/fc128bc0ed436c2295b4a168837bdaa0.svg\" width=\"9\" height=\"12\"\/> \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u043d\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d\/2\" alt=\"d\/2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/902\/c91\/c77\/902c91c777528744f636cecf3d7016f8.svg\" width=\"29\" height=\"22\"\/> \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6df\/f17\/c4e\/6dff17c4e9c2daca4f8d27f778c6eba9.svg\" width=\"9\" height=\"12\"\/> \u0438\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f0a\/74a\/dec\/f0a74adecf1e23449c57279a2eec8e77.svg\" width=\"7\" height=\"16\"\/>. \u0423 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441: \u0435\u0441\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/520\/931\/50f\/52093150f7a34a831dd33ba2403831eb.svg\" width=\"9\" height=\"12\"\/> , \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432 \u043f\u0440\u044f\u043c\u043e\u043c \u0433\u0440\u0430\u0444\u0435 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\" alt=\"s\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a3a\/75d\/60c\/a3a75d60c75f8d9fb5402d18679bd398.svg\" width=\"9\" height=\"12\"\/> \u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0435 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cc9\/362\/b22\/cc9362b22dc72300017b4ec0d382e57e.svg\" width=\"7\" height=\"16\"\/>, \u0442\u043e \u0432\u0441\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u0448\u043b\u0438, \u043d\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/423\/c9b\/d59\/423c9bd59eac31be26c7e28d56dd4d1e.svg\" width=\"9\" height=\"12\"\/> \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u0430 \u043b\u0435\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"z\" alt=\"z\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/276\/936\/a87\/276936a87de1590c4fc78d40b5c04328.svg\" width=\"9\" height=\"12\"\/>, \u043d\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c &#8212; <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s\\rightarrow u\\rightarrow v\\rightarrow t\" alt=\"s\\rightarrow u\\rightarrow v\\rightarrow t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e1\/c7f\/008\/6e1c7f00808e846247ff46d72d1b0ad6.svg\" width=\"126\" height=\"16\"\/>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5a4\/404\/78d\/5a440478d8f87773e9d47b47b27a7636.png\" alt=\"\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442 \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f\" title=\"\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442 \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f\" width=\"533\" height=\"127\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a4\/404\/78d\/5a440478d8f87773e9d47b47b27a7636.png\"\/><\/p>\n<div><figcaption>\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442 \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w_f, w_b\" alt=\"w_f, w_b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f94\/6b4\/6f2\/f946b46f22fb2a5ccd2efe4a27d5053f.svg\" width=\"53\" height=\"17\"\/> \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0432 \u043f\u0440\u044f\u043c\u043e\u043c \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\min_{u, v}w_f(u)+\\ell(u,v)+w_b(v)\" alt=\"\\min_{u, v}w_f(u)+\\ell(u,v)+w_b(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b3\/187\/7cb\/7b31877cbf36d8d6825e0fefc70b9044.svg\" width=\"230\" height=\"34\"\/><\/p>\n<p>\u0422\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u0442.\u0435. \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c\u0443 \u043f\u0443\u0442\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"s=v_0, v_1, \\ldots, v_k \" alt=\"s=v_0, v_1, \\ldots, v_k \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e13\/3af\/60f\/e133af60f6a1e6602042e085c623783b.svg\" width=\"141\" height=\"15\"\/> &#8212; \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u044f\u043c\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t=u_0, \\ldots, u_l\" alt=\"t=u_0, \\ldots, u_l\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c1\/740\/29f\/5c174029f0a4aaee7fe3f16319ad01cf.svg\" width=\"112\" height=\"19\"\/> &#8212; \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435. \u0418\u0437 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043e\u0431\u043e\u0438\u0445, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0435\u0451 \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"z\" alt=\"z\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/87d\/591\/561\/87d591561fdf70147538e405ed310214.svg\" width=\"9\" height=\"12\"\/>. \u041a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v_i\" alt=\"v_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fbe\/06e\/826\/fbe06e8268cd2e3f7bcb4325380aa1ee.svg\" width=\"16\" height=\"15\"\/> \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u_i\" alt=\"u_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1a7\/d77\/56a\/1a7d7756a4569f7c5f8aef1fc81316b1.svg\" width=\"18\" height=\"15\"\/>. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/566\/8c2\/da9\/5668c2da9911bf12dc055c10b07236fa.svg\" width=\"9\" height=\"15\"\/> \u043d\u0435 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d\" alt=\"d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8a7\/a25\/188\/8a7a2518898a6b4ef42318146a952c96.svg\" width=\"10\" height=\"17\"\/> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d(q, t)\\geq d(z, t)\" alt=\"d(q, t)\\geq d(z, t)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bf2\/3b7\/f0a\/bf23b7f0a6b54b6dce339891b68ca881.svg\" width=\"125\" height=\"22\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d(s, q)\\geq d(s, z),\" alt=\"d(s, q)\\geq d(s, z),\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ae\/6dc\/760\/7ae6dc76036ce577fe99aac75e876f34.svg\" width=\"134\" height=\"22\"\/>\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0448\u0438\u043d, \u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 &#8212; \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0442\u0430\u043a\u0438\u0445 \u043f\u0443\u0442\u0435\u0439.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def reversed_graph(graph: Dict[int, Dict[int, float]]) -> Dict[int, Dict[int, float]]:     rev_graph = {v: dict() for v in graph}     for v, adj in graph.items():         for u, l in adj.items():             rev_graph[u][v] = l     return rev_graph  def bidir_dijkstra(graph: Dict[int, Dict[int, float]],                    source: int,                    target: int = None,                    stats: Counter=None):     rev_graph = reversed_graph(graph)     distances_f = {source: 0}     prev_f = dict()     distances_b = {target: 0}     prev_b = dict()     scanned_f = set()     scanned_b = set()          labelled_f = {source}     labelled_b = {target}      best = float(\"inf\")     best_f = source     best_b = target      u = source     v = target          while len(labelled_f) > 0 or len(labelled_b):         if distances_f[u] &lt; distances_b[v]:             if u in scanned_b:                 break             labelled_f.remove(u)             scan(graph, u, distances_f, prev_f, labelled_f, stats)             for p, l in graph[u].items():                 if p in distances_b and distances_f[u] + distances_b[p] + l &lt; best:                     best_f = u                     best_b = p                     best =  distances_f[u] + distances_b[p] + l             scanned_f.add(u)             u = min(labelled_f, key=lambda x: distances_f[x])         else:             if v in scanned_f:                 break             labelled_b.remove(v)             scan(rev_graph, v, distances_b, prev_b, labelled_b, stats)             for p, l in rev_graph[v].items():                 if p in distances_f and distances_b[v] + distances_f[p] + l &lt; best:                     best_f = p                     best_b = v                     best =  distances_b[v] + distances_f[p] + l             scanned_b.add(v)             v = min(labelled_b, key=lambda x: distances_b[x])      best_path = [best_f]     cur = best_f     while cur != source:         cur = prev_f[cur]         best_path.append(cur)     best_path = list(reversed(best_path))      cur = best_b     if cur != best_path[-1]:         best_path.append(cur)     while cur != target:         cur = prev_b[cur]         best_path.append(cur)          return distances_f, distances_b, prev_f, prev_b, best_path, best<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">distances_f, distances_b, prev_f, prev_b, best_path, best = bidir_dijkstra(g, s, t) osmnx.plot.plot_graph_route(G.subgraph(list(distances_f.keys()) + list(distances_b.keys())),                             best_path,                             route_color='g',                             node_size=2,                             node_color='r',                             edge_color='b',                             edge_linewidth=0.2,                             bgcolor='white') <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/12c\/987\/be4\/12c987be4f8bc2a36a795edef583c217.png\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/12c\/987\/be4\/12c987be4f8bc2a36a795edef583c217.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<h2>A*<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b98\/40c\/fa5\/b9840cfa5c5c9089f39789abd0ac3a40.png\" alt=\"\u041f\u0438\u0442\u0435\u0440 \u0425\u0430\u0440\u0442 \u0438 \u041d\u0438\u043b\u044c\u0441 \u041d\u0438\u043b\u044c\u0441\u043e\u043d. \u041f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0438 \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u0435\u0433\u043e A*\" title=\"\u041f\u0438\u0442\u0435\u0440 \u0425\u0430\u0440\u0442 \u0438 \u041d\u0438\u043b\u044c\u0441 \u041d\u0438\u043b\u044c\u0441\u043e\u043d. \u041f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0438 \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u0435\u0433\u043e A*\" width=\"619\" height=\"374\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b98\/40c\/fa5\/b9840cfa5c5c9089f39789abd0ac3a40.png\"\/><\/p>\n<div><figcaption>\u041f\u0438\u0442\u0435\u0440 \u0425\u0430\u0440\u0442 \u0438 \u041d\u0438\u043b\u044c\u0441 \u041d\u0438\u043b\u044c\u0441\u043e\u043d. \u041f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0438 \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u0435\u0433\u043e A*<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u0437\u0430\u0434\u0430\u0447\u0443 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432. \u0414\u0436\u043e\u043d\u0441\u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u044d\u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043a APSP c \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0451\u0431\u0440\u0430\u043c\u0438. \u0414\u043b\u044f APSP\/SSSP \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u043a\u0440\u043e\u043c\u0435 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0451\u0431\u0435\u0440 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442. \u0410 \u0432\u043e\u0442 \u0441 P2P \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438\u043d\u0430\u044f: \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432 \u0443\u0441\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d.<\/p>\n<p><strong>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 1. <\/strong><em>\u0415\u0441\u043b\u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi, \\lambda\" alt=\"\\pi, \\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a56\/81c\/4d9\/a5681c4d9babab79eb66c71ff51f8858.svg\" width=\"31\" height=\"20\"\/><em> \u0442\u0430\u043a\u043e\u0432\u044b, \u0447\u0442\u043e <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda(t)=\\pi(t)=0\" alt=\"\\lambda(t)=\\pi(t)=0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3bf\/917\/976\/3bf917976a9f9a1e09a37f4db504152c.svg\" width=\"127\" height=\"22\"\/><em>  \u0438<\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi(v)\\geq \\lambda(v) ~\\forall v\\in V\" alt=\"\\pi(v)\\geq \\lambda(v) ~\\forall v\\in V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/778\/7f5\/894\/7787f58945582529850494b51e9d440e.svg\" width=\"160\" height=\"22\"\/>, <em>\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0432\u0435\u0440\u0448\u0438\u043d \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa7\/4a3\/215\/aa74a3215d364f10a4128db03eb61db2.svg\" width=\"11\" height=\"12\"\/> <em>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0432\u0435\u0440\u0448\u0438\u043d, \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda\" alt=\"\\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c75\/387\/574\/c753875740d4e892f7e241661d4ae934.svg\" width=\"11\" height=\"17\"\/>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"sv\" alt=\"sv\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ec3\/021\/666\/ec30216662cd86c3c2bcc500c6c8fe90.svg\" width=\"18\" height=\"12\"\/> \u043f\u0443\u0442\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u043b\u0438\u043d\u044b \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"st\" alt=\"st\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/042\/972\/9ae\/0429729aef6ccd4db3e73d0d1d272b11.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi,\" alt=\"\\pi,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/63b\/472\/803\/63b472803ca6070eb8fbb0dd4d99866d.svg\" width=\"16\" height=\"15\"\/> \u0442\u043e \u043e\u043d\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda.\" alt=\"\\lambda.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c57\/f5b\/9fb\/c57f5b9fb442ea15b086cb475ea773d8.svg\" width=\"17\" height=\"17\"\/> \u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/743\/b16\/bbf\/743b16bbfe4d32d24fc8e50d07707880.svg\" width=\"9\" height=\"12\"\/> \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u0430 \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92f\/859\/de2\/92f859de2720289e0ca8ab4385ad7281.svg\" width=\"11\" height=\"12\"\/>, \u0442\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{sv}\" alt=\"P_{sv}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c1\/2c8\/c1c\/9c12c8c1c396b16b2532430b6be6dde2.svg\" width=\"27\" height=\"20\"\/> \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"sv\" alt=\"sv\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/624\/11d\/f2c\/62411df2c17c75fce8b887544b577c77.svg\" width=\"18\" height=\"12\"\/> \u043f\u0443\u0442\u044c, \u0430 \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{st}\" alt=\"P_{st}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/524\/79b\/d52\/52479bd52ca54cc91896007989497ba6.svg\" width=\"26\" height=\"20\"\/> \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"st\" alt=\"st\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/155\/1d7\/a7f\/1551d7a7f1b206a72b71bd9e435825d5.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{array}{rl}\\ell_\\lambda(P_{sv})-\\ell_\\lambda(P_{st})&amp; =\\ell(P_{sv})-\\ell(P_{st})-\\lambda(t)+\\lambda(v)\\\\ &amp; \\leq \\ell(P_{sv})-\\ell(P_{st})-\\lambda(t)+\\pi(v) \\\\ &amp; = \\ell(P_{sv})-\\ell(P_{st})-\\pi(t)+\\pi(v) \\\\ &amp; = \\ell(P_{sv})-\\ell_\\pi(P_{st}) \\\\ &amp; \\leq 0\\end{array}\" alt=\"\\begin{array}{rl}\\ell_\\lambda(P_{sv})-\\ell_\\lambda(P_{st})&amp; =\\ell(P_{sv})-\\ell(P_{st})-\\lambda(t)+\\lambda(v)\\\\ &amp; \\leq \\ell(P_{sv})-\\ell(P_{st})-\\lambda(t)+\\pi(v) \\\\ &amp; = \\ell(P_{sv})-\\ell(P_{st})-\\pi(t)+\\pi(v) \\\\ &amp; = \\ell(P_{sv})-\\ell_\\pi(P_{st}) \\\\ &amp; \\leq 0\\end{array}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dc6\/ac9\/c1f\/dc6ac9c1f0264c7187506493c85caf98.svg\" width=\"427\" height=\"134\"\/><\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e 1) \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b \u043a SSSP \u0441 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438, \u0442\u043e \u0443\u0441\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439; 2) \u0427\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/p>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0435\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e87\/f63\/e3d\/e87f63e3d63c68f7ef094d4a87042f3b.svg\" width=\"11\" height=\"12\"\/> &#8212; \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b \u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi(t)\\leq 0,\" alt=\"\\pi(t)\\leq 0,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f8\/836\/584\/9f8836584db82b4bef72cb60b1443b8a.svg\" width=\"74\" height=\"22\"\/> \u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi(v)\" alt=\"\\pi(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30f\/fe1\/929\/30ffe1929c111bed2220775817d6fada.svg\" width=\"35\" height=\"22\"\/> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0446\u0435\u043d\u043a\u043e\u0439 \u0441\u043d\u0438\u0437\u0443 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"v\" alt=\"v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/05c\/3de\/9fa\/05c3de9fa543262ca4e85275bf54ec91.svg\" width=\"9\" height=\"12\"\/> \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7eb\/309\/57e\/7eb30957e2f289c145c22d05b8bcf450.svg\" width=\"7\" height=\"16\"\/> (\u043d\u043e \u043d\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442). \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u0438\u043d\u0430\u043c\u0438 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: \u0432\u043c\u0435\u0441\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)\" alt=\"w(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd6\/43f\/aa7\/dd643faa75dfc44ec60f9f3b6ef8148f.svg\" width=\"38\" height=\"22\"\/> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w(v)+\\pi(v)\" alt=\"w(v)+\\pi(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2c9\/514\/f9d\/2c9514f9d77c0184254c17d36d5f92f5.svg\" width=\"97\" height=\"22\"\/>&#8212; \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 A*.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 OSM, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b \u0432\u0437\u044f\u0442\u044b \u043a\u0430\u043a \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e (\u0435\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435 \u0433\u0435\u043e\u0434\u0435\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0435) \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import math import geopy.distance  def geo_dist(graph, u, v):     coords_1 = (graph.nodes[u]['y'], graph.nodes[u]['x'])     coords_2 = (graph.nodes[v]['y'], graph.nodes[v]['x'])      return geopy.distance.distance(coords_1, coords_2).m  def a_star(graph: Dict[int, Dict[int, float]],            source: int,            target: int,            graphnx,            stats: Counter=None) -> Tuple[Dict[int, float], Dict[int, int]]:     distances = {source: 0}     prev = dict()     potentials = dict()      labelled = {source}     while len(labelled) > 0:         u = -1         best = -1         for v in labelled:             if v not in potentials:                 potentials[v] = geo_dist(graphnx, v, target)             if u == -1 or distances[v] + potentials[v] &lt; best:                 best = potentials[v] + distances[v]                 u = v         labelled.remove(u)         if u == target:             break         scan(graph, u, distances, prev, labelled, stats)      return distances, prev  distances, prev = a_star(g, s, t, G) print_route_and_visited(G, s, t, distances, prev)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6f4\/ccd\/c02\/6f4ccdc024704ba9c2db7be01206bb49.png\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6f4\/ccd\/c02\/6f4ccdc024704ba9c2db7be01206bb49.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0445\u043e\u0440\u043e\u0448 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c A*? \u041a\u0430\u043a \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0441 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/p>\n<p><strong>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 2.<\/strong> <em>\u0415\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi(v)\" alt=\"\\pi(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/790\/6da\/67b\/7906da67bbc9779a3f63e9efe7a41ee0.svg\" width=\"35\" height=\"22\"\/> &#8212; \u0434\u043b\u0438\u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"vt\" alt=\"vt\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/040\/ad0\/1e0\/040ad01e07a24a44545a14a7aa5bd8b2.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u0438, \u0442\u043e A* c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi\" alt=\"\\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/860\/ce2\/135\/860ce21354ca9e047e9adc329cd0d8d5.svg\" width=\"11\" height=\"12\"\/><em> \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"st\" alt=\"st\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13a\/dd7\/9c9\/13add79c9593bc0c0df380f4187f8704.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u0438<\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(u,v)\" alt=\"(u,v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ee\/35a\/130\/3ee35a130645f34c42b9b512962f61ad.svg\" width=\"44\" height=\"22\"\/> \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"st\" alt=\"st\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/947\/54b\/05e\/94754b05e0cea80598e6ff491f23cc81.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u0438, \u0442\u043e \u0435\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435 \u043b\u0435\u0436\u0438\u0442, \u0442\u043e \u0441\u0442\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f. \u0410* \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u043e\u0439\u0434\u0435\u0442 \u044d\u0442\u0438 \u0440\u0451\u0431\u0440\u0430 \u0438 \u0434\u043e\u0439\u0434\u0435\u0442 \u043f\u043e \u043d\u0438\u043c \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t.\" alt=\"t.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c19\/44a\/9c2\/c1944a9c2e1582e0201b7a511db746b9.svg\" width=\"12\" height=\"16\"\/> <\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t,\" alt=\"t,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/091\/ee2\/785\/091ee2785a965bdf182a0b77c2a57a4a.svg\" width=\"12\" height=\"19\"\/> \u0442\u043e \u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u043d\u0435\u0442. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0435\u0441\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043a\u043e\u0433\u0434\u0430 \u0441\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0435\u0441\u0442\u044c, \u043d\u043e \u043f\u0443\u0442\u0438 \u043d\u0435\u0442, \u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0410* \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0439\u0442\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u0435\u043e\u0440\u0435\u043c\u0443 1 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c, \u0447\u0442\u043e \u0447\u0435\u043c \u0442\u043e\u0447\u043d\u0435\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b, \u0442\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043c\u044b \u043a \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"st\" alt=\"st\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5dd\/d85\/85b\/5ddd8585bc3b87972cc7ef9983790607.svg\" width=\"16\" height=\"16\"\/> \u043f\u0443\u0442\u0438.<\/p>\n<h2>\u0414\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 A*<\/h2>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c9b\/b34\/62b\/c9bb3462bcbf19523743bf8543e4569d.png\" alt=\"\u0425\u0438\u0440\u043e\u0448\u0438 \u0418\u043c\u0430\u0439, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043e\u0430\u0432\u0442\u043e\u0440 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0410*, \u0444\u043e\u0442\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438\" title=\"\u0425\u0438\u0440\u043e\u0448\u0438 \u0418\u043c\u0430\u0439, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043e\u0430\u0432\u0442\u043e\u0440 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0410*, \u0444\u043e\u0442\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438\" width=\"512\" height=\"512\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c9b\/b34\/62b\/c9bb3462bcbf19523743bf8543e4569d.png\"\/><\/p>\n<div><figcaption>\u0425\u0438\u0440\u043e\u0448\u0438 \u0418\u043c\u0430\u0439, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043e\u0430\u0432\u0442\u043e\u0440 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0410*, \u0444\u043e\u0442\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0438 \u0441 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u043a\u043e\u0432\u044b\u0440\u043a\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0410*. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430 \u0434\u043b\u044f \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430, \u0442\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c. \u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi_f(v)+\\pi_b(v)\\equiv const\" alt=\"\\pi_f(v)+\\pi_b(v)\\equiv const\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b71\/fed\/9b0\/b71fed9b0cb412ca9c799244940c5dac.svg\" width=\"182\" height=\"23\"\/>. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\pi_f, \\pi_b,\" alt=\"\\pi_f, \\pi_b,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d66\/22c\/416\/d6622c416e19a3728fdc73331eab4dd8.svg\" width=\"53\" height=\"17\"\/>\u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda_f(v)=\\frac{1}{2}(\\pi_f(v)-\\pi_b(v)),\" alt=\"\\lambda_f(v)=\\frac{1}{2}(\\pi_f(v)-\\pi_b(v)),\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/49e\/24f\/47e\/49e24f47e5fa0b28f6c1e29e216d94db.svg\" width=\"219\" height=\"42\"\/> <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda_b(v)=-\\lambda_f(v)\" alt=\"\\lambda_b(v)=-\\lambda_f(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/346\/42a\/a52\/34642aa52219368723f5d435d0ad5bc7.svg\" width=\"129\" height=\"23\"\/> \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0410* \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def bidir_a_star(graph: Dict[int, Dict[int, float]],                  source: int,                  target: int,                  graphnx,                  stats: Counter=None):     rev_graph = reversed_graph(graph)     distances_f = {source: 0}     prev_f = dict()     distances_b = {target: 0}     prev_b = dict()     scanned_f = set()     scanned_b = set()          labelled_f = {source}     labelled_b = {target}      best = float(\"inf\")     best_f = source     best_b = target      u = source     v = target     potentials = dict()          while len(labelled_f) > 0 or len(labelled_b):         if distances_f[u] &lt; distances_b[v]:             if u in scanned_b:                 break             labelled_f.remove(u)             scan(graph, u, distances_f, prev_f, labelled_f, stats)             for p, l in graph[u].items():                 if p in distances_b and distances_f[u] + distances_b[p] + l &lt; best:                     best_f = u                     best_b = p                     best =  distances_f[u] + distances_b[p] + l             scanned_f.add(u)             for x in labelled_f:                 if x not in potentials:                     potentials[x] = 0.5 * (geo_dist(graphnx, x, target) - geo_dist(graphnx, x, source))             u = min(labelled_f, key=lambda x: distances_f[x] + potentials[x])         else:             if v in scanned_f:                 break             labelled_b.remove(v)             scan(rev_graph, v, distances_b, prev_b, labelled_b, stats)             for p, l in rev_graph[v].items():                 if p in distances_f and distances_b[v] + distances_f[p] + l &lt; best:                     best_f = p                     best_b = v                     best =  distances_b[v] + distances_f[p] + l             scanned_b.add(v)             for x in labelled_b:                 if x not in potentials:                     potentials[x] = 0.5 * (geo_dist(graphnx, x, target) - geo_dist(graphnx, x, source))             v = min(labelled_b, key=lambda x: distances_b[x] - potentials[x])      best_path = [best_f]     cur = best_f     while cur != source:         cur = prev_f[cur]         best_path.append(cur)     best_path = list(reversed(best_path))      cur = best_b     if cur != best_path[-1]:         best_path.append(cur)     while cur != target:         cur = prev_b[cur]         best_path.append(cur)          return distances_f, distances_b, prev_f, prev_b, best_path, best<\/code><\/pre>\n<pre><code class=\"python\">fig, ax = osmnx.plot.plot_graph_route(G.subgraph(list(distances_f.keys()) + list(distances_b.keys())),                                       best_path,                                       route_color='g',                                       node_size=2,                                       node_color='r',                                       edge_color='b',                                       edge_linewidth=0.2,                                       bgcolor='white')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3f4\/e26\/9a3\/3f4e269a3ccfdf5f1e82b5cc23ee4a7d.png\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3f4\/e26\/9a3\/3f4e269a3ccfdf5f1e82b5cc23ee4a7d.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0411\u043e\u043d\u0443\u0441: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 \u0438 \u0433\u0440\u0430\u0444 \u043f\u043e\u0447\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0443\u0442\u0435\u0439<\/h2>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432 \u0438 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f &#8212; \u043d\u0430\u0439\u0442\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a9f\/952\/0e7\/a9f9520e75675d2f44ec2feed43a18c4.svg\" width=\"10\" height=\"17\"\/>\u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439. \u041a\u0430\u043a \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0443 \u0441 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u0430\u043c\u0438 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c\u0443 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0434\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"t,\" alt=\"t,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/130\/668\/113\/1306681130bd83c2494b8473933ef0f9.svg\" width=\"12\" height=\"19\"\/> \u0442\u043e \u043e\u043d \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043d\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0447\u0443\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0432 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0431\u041e\u043b\u044c\u0448\u0438\u043c \u0432\u0435\u0441\u043e\u043c, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dad\/97f\/465\/dad97f465d695f7e25de7ca14c945750.svg\" width=\"10\" height=\"17\"\/> \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439, \u0430 \u043d\u0435 \u043e\u0434\u0438\u043d. \u0412\u043e\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/scholar.google.com\/scholar?hl=ru&amp;as_sdt=0%2C5&amp;q=Space-efficient+data+structures+for+top-k+completion&amp;btnG=\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u0435\u0439\u043a\u0430 \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043c\u0430\u0439\u043a\u0440\u043e\u0441\u043e\u0444\u0442<\/a>, \u0442\u0430\u043c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import heapq  def k_shortest_path_looply(graph: Dict[int, Dict[int, float]],                            source: int,                            target: int,                            k: int,                            min_loop_length: int = 1) -> List[List[int]]:     distances_b, _ = dijkstra(reversed_graph(graph), target)     result = []     sorted_adjacency = dict() # Dict[List[Tuple[int, float]]]     entries = [(source, -1, 0)] # vertex_id, parent entry, sorted adjacency position     path_queue = [(0, 0)] # reduced length, -entry_id       while len(result) &lt; k:         length, entry_id_rev = heapq.heappop(path_queue)         entry_id = -entry_id_rev         v, parent_entry, pos = entries[entry_id]         if v == target:             cur = entry_id             path = [target]             while cur != 0:                 cur = entries[cur][1]                 path.append(entries[cur][0])             result.append(list(reversed(path)))               if v not in sorted_adjacency:             sorted_adjacency[v] = list(sorted(graph[v].items(), key=lambda x: x[1] + distances_b[x[0]]))         if parent_entry != -1 and pos &lt; len(sorted_adjacency[entries[parent_entry][0]]) - 1:             u, length = sorted_adjacency[entries[parent_entry][0]][pos + 1]             cur = parent_entry                         if not has_cycle:                     entries.append((u, parent_entry, pos + 1))                 heapq.heappush(path_queue, (length + distances_b[u] - distances_b[entries[parent_entry][0]], 1 - len(entries)))          if len(sorted_adjacency) > 0:             u, length = sorted_adjacency[v][0]             has_cycle = False             cur = entry_id             for i in range(min_loop_length - 1):                 if cur == 0:                     break                 if entries[cur][0] == u:                     has_cycle = True                     break                 cur = entries[cur][1]             if not has_cycle:                 entries.append((u, entry_id, 0))                 heapq.heappush(path_queue, (length + distances_b[u] - distances_b[v], 1 - len(entries)))      return result<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u044d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044e \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0446\u0438\u043a\u043b\u044b \u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0430\u0444\u0430\u0445, \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 &#8212; \u044d\u0442\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0446\u0438\u043a\u043b\u043e\u043c.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f &#8212; \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u0434\u0433\u0440\u0430\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043f\u0443\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439, \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\alpha.\" alt=\"\\alpha.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/614\/d84\/02a\/614d8402a6e887281cc7934af7841fdb.svg\" width=\"18\" height=\"12\"\/>\u0415\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d_f, d_b\" alt=\"d_f, d_b\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/85f\/0ee\/674\/85f0ee6745bf68432f0e24c4385ccfd8.svg\" width=\"46\" height=\"22\"\/> &#8212; \u043f\u0440\u044f\u043c\u044b\u0435 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0442\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0435\u0431\u0440\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"u, v\" alt=\"u, v\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/618\/fe6\/d00\/618fe6d00b79d29664ce295244765b74.svg\" width=\"29\" height=\"15\"\/> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0433\u0440\u0430\u0444\u0435<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"d_f(u)+\\ell(u, v)+d_b(v)\\leq d_f(t)+\\alpha\" alt=\"d_f(u)+\\ell(u, v)+d_b(v)\\leq d_f(t)+\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb1\/781\/616\/fb17816166c4c8071e9b92dce180cb69.svg\" width=\"290\" height=\"23\"\/><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def best_path_subgraph(graph: Dict[int, Dict[int, float]],                        source: int,                        target: int,                        beam: float) -> List[Tuple[int, int]]:     distances_f, _ = dijkstra(graph, source)     distances_b, _ = dijkstra(reversed_graph(graph), target)     best = distances_f[target]      edges = []     for u, adj in graph.items():         if u not in distances_f:             continue         for v, length in adj.items():             if v not in distances_b:                 continue             if distances_f[u] + length + distances_b[v] &lt; best + beam:                 edges.append((u, v))     return edges    edges = best_path_subgraph(g, s, t, 500)   fig, ax = osmnx.plot.plot_graph(G.edge_subgraph([(u, v, 0) for u, v in edges]),                                 node_size=2,                                 node_color='r',                                 edge_color='b',                                 edge_linewidth=0.2,                                 bgcolor='white')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4d0\/320\/250\/4d03202505b27cc396429cf4ed277572.png\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d0\/320\/250\/4d03202505b27cc396429cf4ed277572.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<h2>ALT <\/h2>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/e5c\/a7f\/5ca\/e5ca7f5ca5dd72d5e4f8f71971d4cd64.jpg\" alt=\"\u042d\u043d\u0434\u0440\u044e \u0413\u043e\u043b\u044c\u0434\u0431\u0435\u0440\u0433, \u0436\u0438\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u043a \u0438 \u043f\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u043a\u0443 \u0432 \u0430\u043c\u0430\u0437\u043e\u043d.\" title=\"\u042d\u043d\u0434\u0440\u044e \u0413\u043e\u043b\u044c\u0434\u0431\u0435\u0440\u0433, \u0436\u0438\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u043a \u0438 \u043f\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u043a\u0443 \u0432 \u0430\u043c\u0430\u0437\u043e\u043d.\" width=\"220\" height=\"308\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e5c\/a7f\/5ca\/e5ca7f5ca5dd72d5e4f8f71971d4cd64.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u042d\u043d\u0434\u0440\u044e \u0413\u043e\u043b\u044c\u0434\u0431\u0435\u0440\u0433, \u0436\u0438\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u043a \u0438 \u043f\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u043a\u0443 \u0432 \u0430\u043c\u0430\u0437\u043e\u043d.<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (\u043d\u043e \u043d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043d\u0430\u0443\u043a\u0435) \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c &#8212; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432 \u0438 A*. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0435\u0435 \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u0432, \u043d\u043e \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b \u043b\u0443\u0447\u0448\u0435? \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 PTP \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0433\u0440\u0430\u0444\u0435, \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u0447\u0435\u0442. \u0412 \u0446\u0435\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 P2P \u043c\u044b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0445\u043e\u0442\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0430\u0442\u0438\u0442 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{O}(m)\" alt=\"\\mathcal{O}(m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/181\/65d\/ddd\/18165ddddb61f14ad6396de5c0c50811.svg\" width=\"47\" height=\"22\"\/> \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u0437\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{o}(m).\" alt=\"\\mathcal{o}(m).\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/56e\/506\/52e\/56e50652e664802273c3120f99469f5a.svg\" width=\"47\" height=\"22\"\/> A* \u0432 \u0446\u0435\u043b\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0432\u044b\u043c, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u0447\u0435\u0442\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0438\u0433\u0440\u044b\u0448\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0418 \u0432\u043e\u0442 \u043c\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 ALT (A*, landmarks, triangle inequality): \u0438\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0434\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eec\/630\/be3\/eec630be3ca10e4bdd0376d671b22433.svg\" width=\"9\" height=\"15\"\/> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u0438\u0437 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"d(s, v)\\leq d(q, v) - d(q, s) \\\\ d(v, t) \\leq d(q, t)-d(q, v)\" alt=\"d(s, v)\\leq d(q, v) - d(q, s) \\\\ d(v, t) \\leq d(q, t)-d(q, v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/685\/9bb\/ebe\/6859bbebea235d28f10a406bdf00fd20.svg\" width=\"697\" height=\"50\"\/><\/p>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <strong>\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0430\u043c\u0438 <\/strong>(landmarks, \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0435\u0441\u0442\u044c \u043b\u0438 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0443\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0439 \u0442\u0435\u0440\u043c\u0438\u043d). \u0425\u043e\u0440\u043e\u0448\u0438\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0432\u0435\u0440\u0448\u0438\u043d, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043e\u0442\u0434\u0430\u043b\u0435\u043d\u0438\u0438. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b, \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 &#8212; \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432<\/p>\n<p><strong>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 3.<\/strong> <em>\u0415\u0441\u043b\u0438 <\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda, \\pi\" alt=\"\\lambda, \\pi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/198\/1c9\/5e3\/1981c95e34ec22caf629d1f475b559d0.svg\" width=\"31\" height=\"20\"\/> &#8212; <em>\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044b, \u0442\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\max(\\pi, \\lambda)\" alt=\"\\max(\\pi, \\lambda)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/acc\/ead\/431\/accead4319a29df75f7b2041ff946ee7.svg\" width=\"82\" height=\"22\"\/> &#8212; \u0442\u043e\u0436\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b.<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\lambda(u)\\leq \\ell(u, v)+\\lambda(v) \\\\ \\pi(u)\\leq \\ell(u, v)+\\pi(v)\" alt=\"\\lambda(u)\\leq \\ell(u, v)+\\lambda(v) \\\\ \\pi(u)\\leq \\ell(u, v)+\\pi(v)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/824\/41a\/7fc\/82441a7fc0d18bdbba046c1dce96aa2a.svg\" width=\"615\" height=\"50\"\/><\/p>\n<p>\u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043a \u043b\u0435\u0432\u043e\u0439 \u0438 \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def alt(graph: Dict[int, Dict[int, float]],         source: int,         target: int,         landmark_distances,         stats: Counter=None):     rev_graph = reversed_graph(graph)     distances_f = {source: 0}     prev_f = dict()     distances_b = {target: 0}     prev_b = dict()     scanned_f = set()     scanned_b = set()          labelled_f = {source}     labelled_b = {target}      best = float(\"inf\")     best_f = source     best_b = target      u = source     v = target     potentials = dict()          while len(labelled_f) > 0 or len(labelled_b):         if distances_f[u] &lt; distances_b[v]:             if u in scanned_b:                 break             labelled_f.remove(u)             scan(graph, u, distances_f, prev_f, labelled_f, stats)             for p, l in graph[u].items():                 if p in distances_b and distances_f[u] + distances_b[p] + l &lt; best:                     best_f = u                     best_b = p                     best =  distances_f[u] + distances_b[p] + l             scanned_f.add(u)             for x in labelled_f:                 if x not in potentials:                     potential_f = 0                     potential_b = 0                     for p in landmark_distances:                         potential_f = max(potential_f, landmark_distances[p][target] - landmark_distances[p][x])                         potential_b = max(potential_b, landmark_distances[p][x] - landmark_distances[p][source])                                       potentials[x] = 0.5 * (potential_f - potential_b)                                      u = min(labelled_f, key=lambda x: distances_f[x] + potentials[x])         else:             if v in scanned_f:                 break             labelled_b.remove(v)             scan(rev_graph, v, distances_b, prev_b, labelled_b, stats)             for p, l in rev_graph[v].items():                 if p in distances_f and distances_b[v] + distances_f[p] + l &lt; best:                     best_f = p                     best_b = v                     best =  distances_b[v] + distances_f[p] + l             scanned_b.add(v)             for x in labelled_b:                 if x not in potentials:                     potential_f = 0                     potential_b = 0                     for p in landmark_distances:                         potential_f = max(potential_f, landmark_distances[p][target] - landmark_distances[p][x])                         potential_b = max(potential_b, landmark_distances[p][x] - landmark_distances[p][source])                                       potentials[x] = 0.5 * (potential_f - potential_b)             v = min(labelled_b, key=lambda x: distances_b[x] - potentials[x])      best_path = [best_f]     cur = best_f     while cur != source:         cur = prev_f[cur]         best_path.append(cur)     best_path = list(reversed(best_path))      cur = best_b     if cur != best_path[-1]:         best_path.append(cur)     while cur != target:         cur = prev_b[cur]         best_path.append(cur)          return distances_f, distances_b, best_path, best<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 OSM<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3e6\/dc3\/856\/3e6dc3856bf03e4a8f042eb6978f25ee.png\" alt=\"\u0422\u043e\u0447\u043a\u0438 \u043f\u043e \u043f\u0435\u0440\u0438\u043c\u0435\u0442\u0440\u0443 -- \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u044b\" title=\"\u0422\u043e\u0447\u043a\u0438 \u043f\u043e \u043f\u0435\u0440\u0438\u043c\u0435\u0442\u0440\u0443 -- \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u044b\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3e6\/dc3\/856\/3e6dc3856bf03e4a8f042eb6978f25ee.png\"\/><\/p>\n<div><figcaption>\u0422\u043e\u0447\u043a\u0438 \u043f\u043e \u043f\u0435\u0440\u0438\u043c\u0435\u0442\u0440\u0443 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u044b<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/details>\n<h2>\u0411\u043e\u043d\u0443\u0441: pathfinding \u0432 \u0438\u0433\u0440\u0430\u0445<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ba2\/aea\/489\/ba2aea4893f9fd0d34f2e67ce75b14f7.png\" alt=\"Battle for Wesnoth\" title=\"Battle for Wesnoth\" width=\"1280\" height=\"768\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba2\/aea\/489\/ba2aea4893f9fd0d34f2e67ce75b14f7.png\"\/><\/p>\n<div><figcaption>Battle for Wesnoth<\/figcaption><\/div>\n<\/figure>\n<p>\u0412 \u043e\u043f\u0435\u043d\u0441\u043e\u0440\u0441 \u0438\u0433\u0440\u0435 Battle for Wesnoth \u044e\u043d\u0438\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0433\u0435\u043a\u0441\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043c\u0438\u0440\u0443, \u043a\u0430\u0436\u0434\u044b\u0439 \u044e\u043d\u0438\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0435\u043a\u0441\u043e\u0432 \u0437\u0430 \u0445\u043e\u0434, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0435\u043a\u0441\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0447\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0443\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/wesnoth\/wesnoth\/blob\/master\/src\/pathfind\/astarsearch.cpp\" rel=\"noopener noreferrer nofollow\">\u0410*<\/a>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/f70\/f86\/c54\/f70f86c5470b7176300dd337baac9b0a.jpg\" alt=\"Heroes of might and magic 3\" title=\"Heroes of might and magic 3\" width=\"800\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f70\/f86\/c54\/f70f86c5470b7176300dd337baac9b0a.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>Heroes of might and magic 3<\/figcaption><\/div>\n<\/figure>\n<p>Heroes of might and magic 3 \u043a\u0430\u0440\u0442\u0430 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0435 \u0442\u0430\u0439\u043b\u044b, \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438 (100 \u043e\u0447\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f), \u043b\u0438\u0431\u043e \u043f\u043e \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 (141 \u043e\u0447\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f). \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0448\u0442\u0440\u0430\u0444\u044b \u0437\u0430 \u043c\u0435\u0441\u0442\u043d\u043e\u0441\u0442\u044c. \u0412 \u043e\u0431\u0449\u0435\u043c \u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u043d\u043e \u0432 \u0438\u0433\u0440\u0435 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0447\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u043b\u0430\u0433 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0430) \u0438 pathfinding \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0430 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0441\u0435\u0433\u043e-\u0442\u043e \u043d\u0430\u0434\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0451\u0431\u0440\u0430\u043c\u0438.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c8d\/31a\/0e2\/c8d31a0e2e0358c4a2746701b41cf4aa.jpg\" alt=\"Warcraft 2000\" title=\"Warcraft 2000\" width=\"359\" height=\"306\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8d\/31a\/0e2\/c8d31a0e2e0358c4a2746701b41cf4aa.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>Warcraft 2000<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u0430\u043a \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0436\u0435 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0443\u0442\u0438 \u0434\u0435\u043b\u044f\u0442 \u043a\u0430\u0440\u0442\u0443 \u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0435 \u0442\u0430\u0439\u043b\u044b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 A*. \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u0445 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044e\u043d\u0438\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u043b\u0438\u0441\u044c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e-\u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e-\u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043d\u0435 \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c2e\/d5b\/6d5\/c2ed5b6d5964b341d51148e031eb486b.jpg\" alt=\"Dota 2\" title=\"Dota 2\" width=\"453\" height=\"339\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c2e\/d5b\/6d5\/c2ed5b6d5964b341d51148e031eb486b.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>Dota 2<\/figcaption><\/div>\n<\/figure>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u0442\u043e\u0440\u044b\u043c \u0438 \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u0432\u0430\u0440\u043a\u0440\u0430\u0444\u0442\u043e\u043c \u0442\u0430\u043a\u0438 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0443\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0410*.<\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0435 \u0432\u043e\u0448\u043b\u0438 \u0441\u0432\u0435\u0436\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a contraction hierarchies \u0438 hub labeling <s>\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044f \u0437\u0430\u043a\u043e\u043b\u0435\u0431\u0430\u043b\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c<\/s>. \u0414\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0447\u0438\u0441\u043b\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0445 scan, relax \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u043c, \u043d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0434\u0430\u0451\u0442 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440<\/p>\n<pre><code>+----------------+-------------+------------------+------------+ |     Method     | Relax calls | Distance updates | Scan calls | +----------------+-------------+------------------+------------+ |     basic      |   1060170   |      437690      |   385509   | |    dijkstra    |    81090    |      34065       |   29730    | | bidir_dijkstra |    52701    |      22416       |   19307    | |     a_star     |    13100    |       5904       |    4764    | |  bidir_a_star  |     8858    |       4160       |    3203    | |      alt       |     1231    |       671        |    463     | +----------------+-------------+------------------+------------+<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0421\u043f\u0438\u0441\u043e\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>Bellman, R. (1958). On a routing problem.\u00a0<em>Quarterly of Applied Mathematics<\/em>,\u00a0<em>16<\/em>(1), 87\u201390.<\/p>\n<p>Cohen, M. B., M\u0105dry, A., Sankowski, P., &amp; Vladu, A. (2017). Negative-weight shortest paths and unit capacity minimum cost flow in \u00f5 (m 10\/7 log w) time*.\u00a0<em>Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms<\/em>, 752\u2013771.<\/p>\n<p>Dantzig, G. B. (1962).\u00a0<em>Linear programming and extensions<\/em>.<\/p>\n<p>Dial, R. B. (1969). Algorithm 360: shortest-path forest with topological ordering [H].\u00a0<em>Commun. ACM<\/em>,\u00a0<em>12<\/em>(11), 632\u2013633. https:\/\/doi.org\/10.1145\/363269.363610<\/p>\n<p>Dijkstra, E. W. (1959). A note on two problems in connexion with graphs.\u00a0<em>Numerische Mathematik<\/em>,\u00a0<em>50<\/em>, 269\u2013271.<\/p>\n<p>Doran, J. (1967). An approach to automatic problem-solving.\u00a0<em>Machine Intelligence<\/em>,\u00a0<em>1<\/em>, 105\u2013127.<\/p>\n<p>Edmonds, J., &amp; Karp, R. M. (1972). Theoretical improvements in algorithmic efficiency for network flow problems.\u00a0<em>Journal of the ACM (JACM)<\/em>,\u00a0<em>19<\/em>(2), 248\u2013264.<\/p>\n<p>Egerv\u00e1ry, E. (1931).\u00a0<em>On combinatorial properties of matrices<\/em>.<\/p>\n<p>Floyd, R. W. (1962). Algorithm 97: Shortest path.\u00a0<em>Commun. ACM<\/em>,\u00a0<em>5<\/em>(6), 345. https:\/\/doi.org\/10.1145\/367766.368168<\/p>\n<p>Ford, L. R. (1956).\u00a0<em>Network flow theory<\/em>.<\/p>\n<p>Ford, L. R., &amp; Fulkerson, D. (1962).\u00a0<em>Flows in Networks<\/em>\u00a0(Vol. 56). Princeton University Press.<\/p>\n<p>Goldberg, A. (2005). Basic shortest path algorithms.\u00a0<em>DIKU Summer School on Shortest Paths. Microsoft Research. Silicon Valey<\/em>.<\/p>\n<p>Goldberg, A. V., &amp; Harrelson, C. (2005). Computing the shortest path: A search meets graph theory.\u00a0<em>SODA<\/em>,\u00a0<em>5<\/em>, 156\u2013165.<\/p>\n<p>Hart, P. E., Nilsson, N. J., &amp; Raphael, B. (1968). A Formal Basis for the Heuristic Determination of Minimum Cost Paths.\u00a0<em>IEEE Transactions on Systems Science and Cybernetics<\/em>,\u00a0<em>4<\/em>(2), 100\u2013107. https:\/\/doi.org\/10.1109\/TSSC.1968.300136<\/p>\n<p>Hsu, B.-J., &amp; Ottaviano, G. (2013). Space-efficient data structures for top-k completion.\u00a0<em>Proceedings of the 22nd International Conference on World Wide Web<\/em>, 583\u2013594.<\/p>\n<p>Ikeda, T., &amp; Imai, H. (1994). Fast a algorithms for multiple sequence alignment.\u00a0<em>Genome Informatics<\/em>,\u00a0<em>5<\/em>, 90\u201399.<\/p>\n<p>Johnson, D. B. (1977). Efficient algorithms for shortest paths in sparse networks.\u00a0<em>Journal of the ACM (JACM)<\/em>,\u00a0<em>24<\/em>(1), 1\u201313.<\/p>\n<p>Le, P. T. H., Truong, N. T. N., Kim, M., So, W., &amp; Jung, J. H. (2018). Applying Theta* in Modern Game.\u00a0<em>J. Comput.<\/em>,\u00a0<em>13<\/em>(5), 527\u2013536.<\/p>\n<p>Moore, E. F. (1959). The shortest path through a maze.\u00a0<em>Proc. of the International Symposium on the Theory of Switching<\/em>, 285\u2013292.<\/p>\n<p>Nicholson, T. A. J. (1966). Finding the shortest route between two points in a network.\u00a0<em>The Computer Journal<\/em>,\u00a0<em>9<\/em>(3), 275\u2013280.<\/p>\n<p>Pohl, I. (1971). Bi-directional Search.\u00a0<em>Machine Intelligence<\/em>,\u00a0<em>6<\/em>, 124\u2013140.<\/p>\n<\/div>\n<\/details>\n<p><a href=\"https:\/\/nbviewer.org\/github\/Malkovsky\/interactive-visualization\/blob\/master\/examples\/osm_shortest_path.ipynb\" rel=\"noopener noreferrer nofollow\">\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432 \u043e\u0434\u043d\u043e\u043c jupyter noteboook<\/a><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c <a href=\"https:\/\/mybinder.org\/v2\/gh\/Malkovsky\/python-examples\/master\" rel=\"noopener noreferrer nofollow\">\u043e\u043d\u043b\u0430\u0439\u043d \u0432 \u0431\u0438\u043d\u0434\u0435\u0440\u0435<\/a> \u0435\u0441\u043b\u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043f\u0438\u0442\u043e\u043d<\/p>\n<h2>P. S.<\/h2>\n<p>\u042f \u043d\u0435 \u0437\u043d\u0430\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u043b\u0438 \u044d\u0442\u043e \u0441 \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b \u0438\u043b\u0438 \u0447\u0435\u043c-\u0442\u043e \u0435\u0449\u0451, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u043c\u0438 \u0432 WYSIWYG &#8212; \u044d\u0442\u043e \u0430\u0434\u0441\u043a\u0430\u044f \u0431\u043e\u043b\u044c. \u0423\u0436\u0435 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u0438\u0441\u0430\u043b\u0438, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043c\u0430, \u043d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430: \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 &#8212; \u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"-\" alt=\"-\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c9a\/6d2\/ade\/c9a6d2ade331982869e2a463fe2ec637.svg\" width=\"15\" height=\"16\"\/>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f.<\/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\/812421\/\"> https:\/\/habr.com\/ru\/articles\/812421\/<\/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<figure class=\"full-width\">\n<div><figcaption>\u041e\u0447\u0435\u043d\u044c \u0442\u043e\u0440\u043e\u043f\u044f\u0449\u0438\u0435\u0441\u044f \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 \u0410 \u0432 \u043f\u0443\u043d\u043a\u0442 \u0411<\/figcaption><\/div>\n<\/figure>\n<p>\u041b\u044e\u0434\u0438 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0441\u0432\u043e\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438. \u041f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u0440\u043e\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0440\u0438\u043c\u0441\u043a\u043e\u0439 \u0438\u043c\u043f\u0435\u0440\u0438\u0438 \u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0435\u0451 \u0440\u0430\u0441\u0446\u0432\u0435\u0442\u0443, \u043d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0440\u043e\u0436\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0431\u044b\u0432\u0430\u044e\u0442 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0435 \u0438\u0437\u044a\u044f\u043d\u044b, \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u043d\u0435\u0431\u0435\u0437\u044b\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%97%D0%B0%D0%B4%D0%B0%D1%87%D0%B0_%D0%BE_%D1%81%D0%B5%D0%BC%D0%B8_%D0%BA%D1%91%D0%BD%D0%B8%D0%B3%D1%81%D0%B1%D0%B5%D1%80%D0%B3%D1%81%D0%BA%D0%B8%D1%85_%D0%BC%D0%BE%D1%81%D1%82%D0%B0%D1%85\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0451\u043d\u0438\u0433\u0441\u0431\u0435\u0440\u0433\u0441\u043a\u0438\u0445 \u043c\u043e\u0441\u0442\u0430\u0445<\/a>, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0442\u0435\u043e\u0440\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u0442\u043e, \u0447\u0442\u043e \u0441 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u0442\u0430\u043b\u0438 \u043e\u0434\u043d\u0438\u043c\u0438 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0442\u0440\u0443\u0434\u0438\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0432\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0446\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0445 \u043d\u0430\u0443\u043a. <em>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438<\/em> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445, \u0437\u0432\u0443\u0447\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0440\u043e\u0433, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0443 \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0438\u0437 \u0433\u043e\u0440\u043e\u0434\u0430 \u0410 \u0432 \u0433\u043e\u0440\u043e\u0434 \u0411 \u043f\u0440\u043e\u0439\u0434\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438 \u0432 1931\u0433., \u0441\u043f\u0443\u0441\u0442\u044f 25 \u043b\u0435\u0442 \u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u0443\u0432\u0430\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043d\u0430 \u0433\u0440\u0430\u0444\u0430\u0445. \u041d\u0430 \u043d\u0451\u043c \u0436\u0435, \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0441\u0442\u043d\u044b, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0438\u0431\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0433\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438\/stackoverflow \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0442\u044c, \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e.<\/p>\n<figure class=\"float\">\n<div><figcaption>\u0416\u0435\u043d\u043e \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u043a\u043e\u0432 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438. \u0412\u0435\u043d\u0433\u0435\u0440\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434 \u042d\u0433\u0435\u0440\u0432\u0430\u0440\u0438-\u041a\u0451\u043d\u0438\u0433\u0430-\u041a\u0443\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430 \u0441 60\u0445 \u0433\u043e\u0434\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043f\u043e\u0447\u0442\u0438 \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442, \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0431\u044b\u043b \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0445\u043e\u0442\u044c \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441 \u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0444\u043e\u043a\u0443\u0441 \u0441\u043c\u0435\u0441\u0442\u0438\u043b\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434 \u043a\u0430\u0442 \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0430\u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u0435\u043d\u044f \u043e\u0433\u043e\u0440\u0447\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0443\u0447\u0451\u0442\u0430 \u0444\u043b\u0430\u0433\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0430 \u0432 HOMM3 \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 \u043f\u0443\u0442\u0438, \u043d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0447\u0442\u043e \u0437\u0430 \u043c\u0443\u0436\u0438\u043a\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u0440\u044f\u0434\u043e\u043c \u0441 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u043e\u0439?  <\/p>\n<h2>\u041f\u0440\u0435\u0430\u043c\u0431\u0443\u043b\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u0430\u043d \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 , \u0433\u0434\u0435  &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u0430  ,  &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u0430  , \u043a\u0430\u0436\u0434\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u043c\u0435\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 ,  &#8212; \u0434\u043b\u0438\u043d\u0430 \u0440\u0435\u0431\u0440\u0430 \u0438\u0437  \u0432  \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0433\u0440\u0430\u0444\u0435.<\/p>\n<p><strong>\u041f\u0443\u0442\u044c <\/strong>\u0438\u0437  \u0432  &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d  \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0440\u0435\u0431\u0440\u043e\u043c. <strong>\u0414\u043b\u0438\u043d\u0430<\/strong> \u043f\u0443\u0442\u0438 &#8212; \u0441\u0443\u043c\u043c\u0430 \u0434\u043b\u0438\u043d \u0440\u0435\u0431\u0451\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u0443\u0442\u0438. <strong>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438:<\/strong> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a-\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0442\u0438 \u043f\u0443\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0434\u043b\u0438\u043d\u044b. \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430  \u0434\u043b\u0438\u043d\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0438\u0437  \u0432 .<\/p>\n<p>\u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>SSSP (single source shortest path): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>APSP (all pair shortest path): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0434\u043e \u0432\u0441\u0435\u0445<\/p>\n<\/li>\n<li>\n<p>P2P (point to point): \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e \u0434\u0440\u0443\u0433\u043e\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 SSSP \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c\u0443 \u043f\u0443\u0442\u0438 \u043e\u0442 \u0438\u0441\u0442\u043e\u043a\u0430 \u0434\u043e \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c  \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u0438\u0437  \u0432  , \u0442\u043e \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440  \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 <strong>\u0434\u0435\u0440\u0435\u0432\u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 <\/strong>&#8212; \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0445\u0440\u0430\u043d\u044f \u0438\u0445 \u0432\u0441\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>\u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0430 \u0433\u0434\u0435  \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e , \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430\/\u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0443\u0433\u043b\u044b\u043c\u0438 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 , \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python, \u0434\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u041e\u041e\u041f \u0433\u0440\u0430\u0444 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 <\/p>\n<pre><code>Dict[int, Dict[int, float]]<\/code><\/pre>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>graph[u][v]<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u0438\u043d\u0435.<\/p>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0431\u0443\u0434\u0443\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 OSM (\u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0432 \u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433\u0435 \u0434\u043e\u0439\u0442\u0438 \u043e\u0442 \u0412\u043b\u0430\u0434\u0438\u043c\u0438\u0440\u0441\u043a\u043e\u0439 \u0434\u043e \u042e\u0431\u0438\u043b\u0435\u0439\u043d\u043e\u0433\u043e)<\/p>\n<details class=\"spoiler\">\n<summary>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 OSM<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import osmnx  G = osmnx.graph_from_point((59.93893094417527, 30.32268115454809), dist=2500) s = 365356365 t = 8518165879 shortest_path = osmnx.routing.shortest_path(G, s, t, weight='length') osmnx.plot.plot_graph_route(G,                             shortest_path,                             route_color='g',                             node_size=2,                             node_color='red',                             edge_color='b',                             edge_linewidth=0.2,                             bgcolor='white')<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b: Scanning method, \u0424\u043e\u0440\u0434-\u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u0423\u043e\u0440\u0448\u0435\u043b\u043b-\u0424\u043b\u043e\u0439\u0434, \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430<\/h2>\n<figure class=\"float\">\n<div><figcaption>\u041b\u0435\u0441\u0442\u0435\u0440 \u0424\u043e\u0440\u0434 \u043c\u043b\u0430\u0434\u0448\u0438\u0439, \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u043f\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438 \u0424\u043e\u0440\u0434\u0430-\u0424\u0430\u043b\u043a\u0435\u0440\u0441\u043e\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u043b\u044f SSSP \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u0424\u043e\u0440\u0434\u043e\u043c \u0432 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0445 \u043f\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u043c. \u0418\u0437-\u0437\u0430 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u0435\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043b\u0438\u0431\u043e <em>scanning method<\/em>, \u043b\u0438\u0431\u043e <em>labelling method <\/em>(\u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0432 \u0440\u0443\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435). \u041c\u0435\u0442\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0432\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0440\u0448\u0438\u043d: <em>\u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435,<\/em>\u0438 <em>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435, <\/em>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b  \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f  \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0443\u0442\u0438  <em>. <\/em>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430  \u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a . \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/p>\n<ul>\n<li>\n<p>: \u0435\u0441\u043b\u0438 w(u)+\\ell(u, v)&#187; alt=&#187;w(v)>w(u)+\\ell(u, v)&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/831\/513\/12b\/83151312bc0fd6bddd53b2ade06cf544.svg&#187; width=&#187;179&#8243; height=&#187;22&#8243;\/> \u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0432 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>: \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c  \u0434\u043b\u044f  \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u0443\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b: <\/strong>\u043f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0451<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 scanning method<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from collections import Counter  def relax(graph: Dict[int, Dict[int, float]],           u: int,           v: int,           distances: Dict[int, float],           prev: Dict[int, int],           labelled: Set,           stats: Counter = None):     if stats is not None:         stats[\"relax_calls\"] += 1     if v not in distances or distances[v] > distances[u] + graph[u][v]:         if stats is not None:             stats[\"distance_updates\"] += 1         distances[v] = distances[u] + graph[u][v]         prev[v] = u         labelled.add(v)  def scan(graph: Dict[int, Dict[int, float]],          node: int,          distances: Dict[int, float],          prev: Dict[int, int],          labelled: Set,          stats: Counter = None):     if stats is not None:         stats[\"scan_calls\"] += 1              for other, length in graph[node].items():         relax(graph, node, other, distances, prev, labelled, stats)     # labelled.remove(node)  def scanning_method(graph: Dict[int, Dict[int, float]],                     source: int,                     target: int = None,                     stats: Counter = None):     distances = {source: 0}     prev = dict()     labelled = {source}     while len(labelled) > 0:         u = labelled.pop()         if u == target:             break         scan(graph, u, distances, prev, labelled, stats)      return distances, prev<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0441\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u0435\u0440\u0448\u0438\u043d \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043d\u044b\u043c\u0438 \u0441\u043b\u0443\u0447\u0430\u044f\u043c\u0438 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 scanning method<\/summary>\n<div class=\"spoiler__content\">\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f  \u043d\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0445\u043e\u0434\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442  , \u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0443\u0442\u044c \u043e\u0442  \u0434\u043e  \u0441 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c . \u041f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u043d\u0435\u043c \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/strong>: \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u0432\u0435\u0440\u0448\u0438\u043d\u0443  \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u043d\u0435\u0451 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0443\u0442\u0435\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0442\u043e \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u0430  \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f  \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c, \u0430 \u043c\u043e\u0433\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f  \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f  \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438  \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e, \u0430  \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c<\/strong>: \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0422\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0430\u0440\u0430 \u0432\u0435\u0440\u0448\u0438\u043d, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435, \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 (\u0432\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0439\u0442\u0438\u0441\u044c \u0438\u0431\u043e \u0434\u043b\u044f  \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e) \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043e\u0442  \u0434\u043e  \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 . \u0422\u043e\u0433\u0434\u0430 w(u)+\\ell(u, v)&#187; alt=&#187;w(v)>w(u)+\\ell(u, v)&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e0e\/2b2\/420\/e0e2b2420fe884506e3340a20fc247fb.svg&#187; width=&#187;179&#8243; height=&#187;22&#8243;\/> \u0447\u0442\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u043f\u0443\u043d\u043a\u0442\u0443 4 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<figure class=\"float\">\n<div><figcaption>\u0420\u0438\u0447\u0430\u0440\u0434 \u0411\u0435\u043b\u043b\u043c\u0430\u043d, \u043e\u0442\u0435\u0446 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 &#8212; \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u0447\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e, \u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u0412\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u043a\u0430\u043a \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0442\u0430\u043a \u0438 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 <strong>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 <\/strong>&#8212; \u043e\u0431\u0449\u0435\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0440\u044f\u0434\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0420\u0438\u0447\u0430\u0440\u0434\u043e\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u043e\u043c. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 &#8212; \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043e\u043d \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0434\u0438\u0439. \u041d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438  \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0430 \u043f\u0443\u0442\u044f\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c  \u0440\u0451\u0431\u0435\u0440. \u0415\u0441\u043b\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0437\u0430  \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442  \u0434\u043e  \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c  \u0448\u0430\u0433\u043e\u0432, \u0442\u043e  \u043f\u0440\u0438  \u0438, \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, . \u0421\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 (\u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0435) \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435  \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043c\u0430\u043b\u044b\u0445 , \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0434\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 , \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0434\u0438\u0439 , \u0447\u0442\u043e \u0434\u0430\u0451\u0442 \u043e\u0446\u0435\u043d\u043a\u0443  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 &#8212; \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f   \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0434\u043b\u044f  \u0442\u0430\u043a \u0435\u0449\u0435 \u0438 \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0430\u0434\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0424\u043e\u0440\u0434\u0430-\u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def bellman_ford_moore(graph: Dict[int, Dict[int, float]],                        source: int) -> Tuple[Dict[int, float], Dict[int, int]]:     distances = {source: 0}     prev = dict()     changed = True     for k in graph:         if not changed:             break         changed = False         for u, adjacent in graph.items():             if u not in distances:                 continue             for v, l in adjacent.items():                 if v not in<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-375470","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375470","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=375470"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375470\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}