{"id":297262,"date":"2020-01-17T15:00:11","date_gmt":"2020-01-17T15:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297262"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-01-17T15:00:11","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297262","title":{"rendered":"\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/484382\/\"><i>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/fQmF\/\">\u00ab\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432\u00bb<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/i>  <\/p>\n<hr>\n<p>   <b>\u0417\u0430\u0434\u0430\u0447\u0430<\/b>: \u0414\u0430\u043d \u0433\u0440\u0430\u0444 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 src \u0432 \u0433\u0440\u0430\u0444\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 src \u0434\u043e \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0435. \u0412 \u0433\u0440\u0430\u0444\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0431\u0440\u0430 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438.<\/p>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0436\u0430\u0434\u043d\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u0430 \u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0432\u043d\u0430 O(VLogV) (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u0443\u0447\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438). \u041e\u0434\u043d\u0430\u043a\u043e \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0433\u0440\u0430\u0444\u043e\u0432 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438 \u0440\u0435\u0431\u0435\u0440, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0411\u0435\u043b\u043b\u043c\u0430\u043d-\u0424\u043e\u0440\u0434 \u2014 \u0432\u043f\u043e\u043b\u043d\u0435. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b, \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0432\u043d\u0430 <i>O(VE)<\/i>, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b.<\/p>\n<p>  <b>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f<\/b>: \u041f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 <a href=\"https:\/\/practice.geeksforgeeks.org\/problems\/negative-weight-cycle\/0\">\u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f<\/a> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<br \/>  <a name=\"habracut\"><\/a>   <\/p>\n<h3>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p>   \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0448\u0430\u0433\u0438.<\/p>\n<p>  <i>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/i>: \u0413\u0440\u0430\u0444 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 <code>src<\/code>.<br \/>   <i>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/i>: \u041a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u043e\u0442 src. \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430, \u0442\u043e \u0441\u0430\u043c\u044b\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f, \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.<\/p>\n<ol>\n<li>\u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0442 \u0438\u0441\u0445\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 \u0432\u0435\u0440\u0448\u0438\u043d, \u043a\u0430\u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435, \u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e src \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c 0. \u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <code>dist[]<\/code> \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <code>|V|<\/code> \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0440\u0430\u0432\u043d\u044b\u043c\u0438 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>dist[src]<\/code>, \u0433\u0434\u0435 <code>src<\/code> \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430.<\/li>\n<li>\u0412\u0442\u043e\u0440\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <code>|V|<\/code>-1 \u0440\u0430\u0437, \u0433\u0434\u0435 <code>|V|<\/code> \u2014 \u0447\u0438\u0441\u043b\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0435.<br \/> \n<ul>\n<li>\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0431\u0440\u0430 <i>u-v<\/i>:<br \/>   \u0415\u0441\u043b\u0438 <code>dist[v] &gt; dist[u] + \u0432\u0435\u0441 \u0440\u0435\u0431\u0440\u0430 uv<\/code>, \u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 <code>dist[v]<\/code><br \/>   <code>dist [v] = dist [u] + \u0432\u0435\u0441 \u0440\u0435\u0431\u0440\u0430 uv<\/code>  <\/li>\n<\/ul>\n<\/li>\n<li>\u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f, \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0432 \u0433\u0440\u0430\u0444\u0435 \u0446\u0438\u043a\u043b \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0431\u0440\u0430 <i>u-v<\/i> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<br \/> \n<ul>\n<li>\u0415\u0441\u043b\u0438 <code>dist[v] &gt; dist[u] + \u0432\u0435\u0441 \u0440\u0435\u0431\u0440\u0430 uv<\/code>, \u0442\u043e \u0432 \u0433\u0440\u0430\u0444\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0438\u043a\u043b \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430.  <\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>  \u0418\u0434\u0435\u044f \u0448\u0430\u0433\u0430 3 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0448\u0430\u0433 2 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0433\u0440\u0430\u0444 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0438\u043a\u043b\u0430 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043f\u0435\u0440\u0435\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u0440\u0435\u0431\u0440\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043f\u0443\u0442\u044c \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0432\u0435\u0440\u0448\u0438\u043d, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u043c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0446\u0438\u043a\u043b\u0430 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430.<\/p>\n<p>  \u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u041a\u0430\u043a \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \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, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0441\u043d\u0438\u0437\u0443 \u0432\u0432\u0435\u0440\u0445. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0443\u0442\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c \u0432 \u043e\u0434\u043d\u043e \u0440\u0435\u0431\u0440\u043e. \u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0434\u0432\u0443\u0445 \u0440\u0435\u0431\u0435\u0440 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u041f\u043e\u0441\u043b\u0435 <i>i<\/i>-\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435<i> i <\/i>\u0440\u0435\u0431\u0435\u0440. \u0412 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0443\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c <i>|V|-1<\/i> \u0440\u0435\u0431\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0446\u0438\u043a\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e <i>|V|-1<\/i> \u0440\u0430\u0437. \u0418\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043b\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0443\u0442\u044c \u0441 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c <i>i<\/i> \u0440\u0435\u0431\u0440\u0430\u043c\u0438, \u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0435\u0431\u0440\u0430\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0441 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c <i>i + 1<\/i> \u0440\u0435\u0431\u0440\u0430\u043c\u0438 (\u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0441\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <a href=\"http:\/\/courses.csail.mit.edu\/6.006\/spring11\/lectures\/lec15.pdf\">\u044d\u0442\u0443<\/a> \u043b\u0435\u043a\u0446\u0438\u044e \u0438\u043b\u0438 <a href=\"http:\/\/www.youtube.com\/watch?v=Ttezuzs39nk\">\u0432\u0438\u0434\u0435\u043e\u043b\u0435\u043a\u0446\u0438\u044e \u043e\u0442 MIT<\/a>)<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 <\/h4>\n<p>   \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0433\u0440\u0430\u0444\u0430. \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u0437\u044f\u0442\u044b <a href=\"http:\/\/www.cs.arizona.edu\/classes\/cs445\/spring07\/ShortestPath2.prn.pdf\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>.<br \/>   \u041f\u0443\u0441\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0440\u0430\u0432\u043d\u0430 0. \u041f\u0440\u0438\u043c\u0438\u0442\u0435 \u0432\u0441\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0437\u0430 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435, \u043a\u0440\u043e\u043c\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u0441\u0430\u043c\u043e\u0439 <code>src<\/code>. \u041e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0432 \u0433\u0440\u0430\u0444\u0435 \u0440\u0430\u0432\u043d\u043e 5, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0440\u0435\u0431\u0440\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438 4 \u0440\u0430\u0437\u0430. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mc\/by\/aj\/mcbyaj-zot8xgs3op0eytzy_j9s.png\"><\/p>\n<p>   \u041f\u0443\u0441\u0442\u044c \u0440\u0435\u0431\u0440\u0430 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435: (B, E), (D, B), (B, D), (A, B), (A, C), (D, C), (B, C), (E, D). \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0440\u0435\u0431\u0440\u0430\u043c \u0431\u044b\u043b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0431\u0440\u0430 (B, E), (D, B), (B, D) \u0438 (A, B) \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u0422\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 (A, C). \u0427\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f (D, C), (B, C) \u0438 (E, D).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fw\/qg\/_a\/fwqg_a7bjrpgdazxqkyrlus_hg8.png\"><\/p>\n<p>   \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0430\u043c\u044b\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043f\u0443\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435 \u0434\u043b\u0438\u043d\u043d\u0435\u0435 \u043f\u0443\u0442\u0438 \u0432 1 \u0440\u0435\u0431\u0440\u043e. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0435\u0431\u0440\u0430\u043c (\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ay\/vn\/oc\/ayvnoc7tqegmemompcimnftttk4.png\"><\/p>\n<p>   \u0412\u0442\u043e\u0440\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 2 \u0440\u0435\u0431\u0435\u0440. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0435\u0431\u0440\u0430\u043c \u0435\u0449\u0435 2 \u0440\u0430\u0437\u0430. \u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0440\u0435\u0442\u044c\u044f \u0438 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439.<br \/>   \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\"># Python program for Bellman-Ford's single source  # shortest path algorithm.   from collections import defaultdict   # Class to represent a graph  class Graph:   \tdef __init__(self, vertices):  \t\tself.V = vertices # No. of vertices  \t\tself.graph = [] # default dictionary to store graph   \t# function to add an edge to graph  \tdef addEdge(self, u, v, w):  \t\tself.graph.append([u, v, w])  \t\t \t# utility function used to print the solution  \tdef printArr(self, dist):  \t\tprint(&quot;Vertex Distance from Source&quot;)  \t\tfor i in range(self.V):  \t\t\tprint(&quot;% d \\t\\t % d&quot; % (i, dist[i]))  \t \t# The main function that finds shortest distances from src to  \t# all other vertices using Bellman-Ford algorithm. The function  \t# also detects negative weight cycle  \tdef BellmanFord(self, src):   \t\t# Step 1: Initialize distances from src to all other vertices  \t\t# as INFINITE  \t\tdist = [float(&quot;Inf&quot;)] * self.V  \t\tdist[src] = 0   \t\t# Step 2: Relax all edges |V| - 1 times. A simple shortest  \t\t# path from src to any other vertex can have at-most |V| - 1  \t\t# edges  \t\tfor i in range(self.V - 1):  \t\t\t# Update dist value and parent index of the adjacent vertices of  \t\t\t# the picked vertex. Consider only those vertices which are still in  \t\t\t# queue  \t\t\tfor u, v, w in self.graph:  \t\t\t\tif dist[u] != float(&quot;Inf&quot;) and dist[u] + w &lt; dist[v]:  \t\t\t\t\t\tdist[v] = dist[u] + w   \t\t# Step 3: check for negative-weight cycles. The above step  \t\t# guarantees shortest distances if graph doesn't contain  \t\t# negative weight cycle. If we get a shorter path, then there  \t\t# is a cycle.   \t\tfor u, v, w in self.graph:  \t\t\t\tif dist[u] != float(&quot;Inf&quot;) and dist[u] + w &lt; dist[v]:  \t\t\t\t\t\tprint &quot;Graph contains negative weight cycle&quot; \t\t\t\t\t\treturn \t\t\t\t\t\t \t\t# print all distance  \t\tself.printArr(dist)   g = Graph(5)  g.addEdge(0, 1, -1)  g.addEdge(0, 2, 4)  g.addEdge(1, 2, 3)  g.addEdge(1, 3, 2)  g.addEdge(1, 4, 2)  g.addEdge(3, 2, 5)  g.addEdge(3, 1, 1)  g.addEdge(4, 3, -3)   # Print the solution  g.BellmanFord(0)   # This code is contributed by Neelam Yadav <\/code><\/pre>\n<p>  <b> \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<br \/>  <\/b><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jm\/zw\/tb\/jmzwtbctl4wb4fvukrfgrl7keyu.png\"><\/p>\n<p>   <b>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f:<\/b><\/p>\n<ol>\n<li>\u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0441\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0433\u0440\u0430\u0444\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0443\u0442\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0433\u043e\u0434\u0443, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. <\/li>\n<li>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0435 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c (\u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b). \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b, \u0433\u0434\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d, \u0432 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0435-\u0424\u043e\u0440\u0434\u0435 \u0440\u0435\u0431\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443.<\/li>\n<\/ol>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f:<\/b><\/p>\n<ol>\n<li>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u0446\u0438\u043a\u043b\u043e\u0432 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430. \u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0435\u0433\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0441\u043e\u043e\u0431\u0449\u0430\u043b \u043e \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.<\/li>\n<li>\u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 \u0432 \u0433\u0440\u0430\u0444\u0435 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438? \u0415\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0438\u0434\u0435\u044f: \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u0430, \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0440\u0430\u0432\u043d\u043e\u0435 \u043c\u043e\u0434\u0443\u043b\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430) \u043a\u043e \u0432\u0441\u0435\u043c \u0432\u0435\u0441\u0430\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430. \u0421\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c?<\/li>\n<\/ol>\n<p>  <a href=\"https:\/\/www.geeksforgeeks.org\/bellman-ford-algorithm-simple-implementation\/\">\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430<\/a><\/p>\n<p>  <b>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/b><\/p>\n<p>  <a href=\"http:\/\/www.youtube.com\/watch?v=Ttezuzs39nk\">www.youtube.com\/watch?v=Ttezuzs39nk<\/a><br \/>  <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bellman%E2%80%93Ford_algorithm\">en.wikipedia.org\/wiki\/Bellman%E2%80%93Ford_algorithm<\/a><br \/>  <a href=\"http:\/\/www.cs.arizona.edu\/classes\/cs445\/spring07\/ShortestPath2.prn.pdf\">www.cs.arizona.edu\/classes\/cs445\/spring07\/ShortestPath2.prn.pdf<\/a><\/div>\n<p> \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\/company\/otus\/blog\/484382\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/484382\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/484382\/\"><i>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/fQmF\/\">\u00ab\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432\u00bb<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/i>  <\/p>\n<hr>\n<p>   <b>\u0417\u0430\u0434\u0430\u0447\u0430<\/b>: \u0414\u0430\u043d \u0433\u0440\u0430\u0444 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 src \u0432 \u0433\u0440\u0430\u0444\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442 src \u0434\u043e \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0435. \u0412 \u0433\u0440\u0430\u0444\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0431\u0440\u0430 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438.<\/p>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0436\u0430\u0434\u043d\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u0430 \u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0432\u043d\u0430 O(VLogV) (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u0443\u0447\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438). \u041e\u0434\u043d\u0430\u043a\u043e \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0433\u0440\u0430\u0444\u043e\u0432 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438 \u0440\u0435\u0431\u0435\u0440, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0411\u0435\u043b\u043b\u043c\u0430\u043d-\u0424\u043e\u0440\u0434 \u2014 \u0432\u043f\u043e\u043b\u043d\u0435. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430-\u0424\u043e\u0440\u0434\u0430 \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b, \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0432\u043d\u0430 <i>O(VE)<\/i>, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u044b.<\/p>\n<p>  <b>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f<\/b>: \u041f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 <a href=\"https:\/\/practice.geeksforgeeks.org\/problems\/negative-weight-cycle\/0\">\u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f<\/a> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297262","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297262","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=297262"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297262\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}