{"id":341662,"date":"2022-11-24T15:00:30","date_gmt":"2022-11-24T15:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341662"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341662","title":{"rendered":"<span>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0446\u0441\u0435\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<h3>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h3>\n<p>\u0411\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c, \u044f \u0440\u0435\u0448\u0438\u043b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0443\u0440\u0441\u043e\u0432\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f \u0441\u043e\u0446\u0441\u0435\u0442\u0438. \u041c\u043d\u0435 \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c, \u043d\u0430\u0447\u0430\u043b \u043f\u043e\u0438\u0441\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/132558\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0442\u0435\u043e\u0440\u0438\u044f \u0448\u0435\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u043f\u043e\u0436\u0430\u0442\u0438\u0439<\/a>, \u0442\u0430\u043c \u0431\u044b\u043b\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0438\u0434\u0435\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B2%D1%83%D0%BD%D0%B0%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9_%D0%BF%D0%BE%D0%B8%D1%81%D0%BA\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430<\/a>, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0441\u0430\u043c\u044b\u043c \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<h3>\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d5\/d7a\/1bd\/3d5d7a1bd052fd864df252277c76e0fd.svg\" width=\"12\" height=\"17\"\/><\/strong>(<em>source<\/em>) \u2014 <em>id<\/em> \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\" alt=\"SF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/884\/8a1\/a3a\/8848a1a3a92b84202500ecc36f002ffb.svg\" width=\"27\" height=\"17\"\/><\/strong>(<em>source friends<\/em>) \u2014 \u0441\u043f\u0438\u0441\u043e\u043a <em>id<\/em> \u0434\u0440\u0443\u0437\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/52e\/688\/cee\/52e688cee65a1b97f280d3196342f5f4.svg\" width=\"14\" height=\"17\"\/><\/strong>(<em>target<\/em>) \u2014 <em>id<\/em> \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"TF\" alt=\"TF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/565\/7ac\/3d4\/5657ac3d447d12296146ff8065cfa068.svg\" width=\"28\" height=\"17\"\/><\/strong>(<em>target friend<\/em>s) \u2014 \u0441\u043f\u0438\u0441\u043e\u043a <em>id<\/em> \u0434\u0440\u0443\u0437\u0435\u0439 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bdb\/302\/d99\/bdb302d9907725dfbb236dda783499a4.svg\" width=\"20\" height=\"17\"\/><\/strong>(<em>mutual friend<\/em>) \u2014 \u0441\u0430\u043c\u044b\u0439 \u0434\u0430\u043b\u044c\u043d\u0438\u0439 \u043e\u0431\u0449\u0438\u0439 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439, \u0442.\u0435. \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/460\/680\/adf\/460680adf82128c148bab2476c52a6d1.svg\" width=\"12\" height=\"17\"\/><\/strong>\u0434\u043e <strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d6\/a31\/ced\/9d6a31cedac62b4ed8b2767014e4ce10.svg\" width=\"20\" height=\"17\"\/><\/strong>\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/15b\/97d\/451\/15b97d45167cd59ffbebc451dd0b3c6d.svg\" width=\"14\" height=\"17\"\/><\/strong>\u0434\u043e <strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/985\/8a9\/59c\/9858a959cab0d23714fb50bc330c06a6.svg\" width=\"20\" height=\"17\"\/><\/strong><em><u>\u0440\u0430\u0432\u043d\u044b<\/u><\/em> \u043b\u0438\u0431\u043e <em><u>\u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 1<\/u><\/em><\/p>\n<h3>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p><strong>0.<\/strong>\u00a0\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/162\/bf2\/886\/162bf288695df45982ce74470c5d2700.svg\" width=\"12\" height=\"17\"\/><\/strong>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dea\/9b3\/b91\/dea9b3b911e10c4c30e918d0ae45d88f.svg\" width=\"14\" height=\"17\"\/>\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:<br \/>  <strong><em>1*.<\/em><\/strong> \u0415\u0441\u043b\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\\in TF\" alt=\"S\\in TF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a08\/a97\/afb\/a08a97afb2edd294b20cc55b52d04a23.svg\" width=\"64\" height=\"17\"\/>\u0438\u043b\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\\in SF\" alt=\"T\\in SF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e46\/3a1\/ffa\/e463a1ffa99bed081cabe97fd77f5c08.svg\" width=\"64\" height=\"17\"\/>, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,F]\" alt=\"[S,F]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f9\/82a\/36c\/1f982a36cd2c86f6fee157c821ed413b.svg\" width=\"46\" height=\"22\"\/><br \/>  <strong><em>2*.<\/em><\/strong> \u0415\u0441\u043b\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\\cap TF\\neq\\varnothing\" alt=\"SF\\cap TF\\neq\\varnothing\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d28\/4ae\/eea\/d284aeeeaf47327a7544eea7606ead30.svg\" width=\"117\" height=\"21\"\/>, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,m,F]\" alt=\"[S,m,F]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/198\/57a\/651\/19857a651467130e1cf600df04661dc3.svg\" width=\"72\" height=\"22\"\/>, \u0433\u0434\u0435<strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e77\/af3\/956\/e77af39564c67ac2558128d7ecb4c298.svg\" width=\"17\" height=\"12\"\/><\/strong>\u2014 \u043b\u044e\u0431\u043e\u0435 <em>id<\/em> \u0438\u0437<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\\cap TF\" alt=\"SF\\cap TF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9fb\/9ff\/3bb\/9fb9ff3bb0058750157f4823844273b2.svg\" width=\"76\" height=\"17\"\/><br \/>  <strong><em>3*.<\/em><\/strong> \u0415\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e <strong><em>1*<\/em><\/strong> \u0438 <strong><em>2*<\/em><\/strong>, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>1<\/p>\n<p>1. <\/strong>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f9\/555\/699\/1f9555699ffaa60b62ea3c66b4564f36.svg\" width=\"14\" height=\"17\"\/>, \u0442.\u0435. \u0441\u043c\u043e\u0442\u0440\u0438\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\\cap T_iF\" alt=\"SF\\cap T_iF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/252\/8be\/10a\/2528be10a0afc806c5dbec79dc65475e.svg\" width=\"81\" height=\"20\"\/>, \u0433\u0434\u0435<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T_i\\in TF\" alt=\"T_i\\in TF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c71\/39d\/9d3\/c7139d9d3bd8b25018003f5c93c62a1a.svg\" width=\"69\" height=\"20\"\/>. \u0415\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T_i\" alt=\"T_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6bd\/81b\/798\/6bd81b798120354c0bf278ee7192c9f9.svg\" width=\"18\" height=\"20\"\/>, \u0447\u0442\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\\cap T_iF\\neq\\varnothing\" alt=\"SF\\cap T_iF\\neq\\varnothing\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/162\/b18\/562\/162b18562da9d9a4998aea7bf75f4365.svg\" width=\"121\" height=\"21\"\/>, \u0442\u043e\u0433\u0434\u0430<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M=T_i\" alt=\"M=T_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f1\/d8e\/af9\/0f1d8eaf9d686c1e71276daac02661aa.svg\" width=\"64\" height=\"20\"\/> \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>3<\/strong>, \u0438\u043d\u0430\u0447\u0435 <br \/><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"TF=\\{T_iF|i=\\overline{1,|TF|}\\}\" alt=\"TF=\\{T_iF|i=\\overline{1,|TF|}\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/67a\/2fd\/f6e\/67a2fdf6eac53a527d9d28b486e934b8.svg\" width=\"201\" height=\"28\"\/>\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>2<\/p>\n<p>2. <\/strong>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b4e\/165\/ab9\/b4e165ab9b9b1efebbe39d2109a9373b.svg\" width=\"12\" height=\"17\"\/>, \u0442.\u0435. \u0441\u043c\u043e\u0442\u0440\u0438\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"TF\\cap S_iF\" alt=\"TF\\cap S_iF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2e6\/7c5\/740\/2e67c574036fe6f812ade34bb592e30b.svg\" width=\"82\" height=\"20\"\/>, \u0433\u0434\u0435<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S_i\\in SF\" alt=\"S_i\\in SF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/494\/f43\/2ae\/494f432ae09161ad386eb17a6b740bec.svg\" width=\"69\" height=\"20\"\/>. \u0415\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S_i\" alt=\"S_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/04c\/d3d\/5af\/04cd3d5af12538429d903f167e24c9d2.svg\" width=\"18\" height=\"20\"\/>, \u0447\u0442\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"TF\\cap S_iF\\neq\\varnothing\" alt=\"TF\\cap S_iF\\neq\\varnothing\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e7d\/385\/aa9\/e7d385aa963e50d7752b47219b4cff04.svg\" width=\"123\" height=\"21\"\/>, \u0442\u043e\u0433\u0434\u0430<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M=S_i\" alt=\"M=S_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7db\/776\/833\/7db776833d1629ebe5066f14f2015a40.svg\" width=\"64\" height=\"20\"\/> \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>3<\/strong>, \u0438\u043d\u0430\u0447\u0435 <br \/><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF=\\{S_iF|i=\\overline{1,|SF|}\\}\" alt=\"SF=\\{S_iF|i=\\overline{1,|SF|}\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4da\/eda\/ee3\/4daedaee3ee0f76713f66c91e2f78119.svg\" width=\"199\" height=\"28\"\/>\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>1<\/p>\n<p>3. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f6\/33e\/415\/8f633e4159d879cdcaa33a09ad2a04cf.svg\" width=\"20\" height=\"17\"\/>, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,\u2026, M,\u2026, T]\" alt=\"[S,\u2026, M,\u2026, T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6bc\/317\/e14\/6bc317e149d89c5adece7ff453da3b59.svg\" width=\"143\" height=\"22\"\/>. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0446\u0435\u043f\u043e\u0447\u043a\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S, \u2026, M]\" alt=\"[S, \u2026, M]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d9d\/cca\/b02\/d9dccab02c61b95f0b85226198cac24f.svg\" width=\"86\" height=\"22\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[M, \u2026, T]\" alt=\"[M, \u2026, T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/54a\/cb8\/a68\/54acb8a68071bf6983e10558c7da2f69.svg\" width=\"88\" height=\"22\"\/>\u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1<\/strong> \u0434\u043b\u044f \u043f\u0430\u0440<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/160\/66d\/ed6\/16066ded600e93cb7cbe17fa8d1948b2.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/668\/4af\/674\/6684af674780f10c171bf5612ab9e6a5.svg\" width=\"20\" height=\"17\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c1c\/861\/cca\/c1c861ccae8ed1993aedb83cd85a3662.svg\" width=\"20\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e3c\/5f8\/97a\/e3c5f897ae590ec04115b6163023e4d9.svg\" width=\"14\" height=\"17\"\/>. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/00e\/06a\/1bb\/00e06a1bbac429cbf48aeede220055bf.svg\" width=\"27\" height=\"19\"\/>\u0434\u043b\u044f  \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e28\/d7e\/8a1\/e28d7e8a12bb4d0a7698c9f797a78955.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/967\/3ac\/f05\/9673acf058cd1cb76c8b87cdd2a97527.svg\" width=\"20\" height=\"17\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d89\/eab\/b12\/d89eabb126d799af6be00d20cd18b615.svg\" width=\"27\" height=\"19\"\/>\u0434\u043b\u044f \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b42\/cc4\/bac\/b42cc4baca6214012f2fa04bd31ef6a2.svg\" width=\"20\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd3\/2fb\/339\/cd32fb3395cb586e8a5efeb91153191e.svg\" width=\"14\" height=\"17\"\/>.<\/p>\n<p><strong>4. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c10\/51d\/5bb\/c1051d5bb67bda2a4140581206fc38ef.svg\" width=\"27\" height=\"19\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ffa\/85b\/d4b\/ffa85bd4b7767207ffd483b9468477ad.svg\" width=\"27\" height=\"19\"\/>, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,...,M_1,...,M,...,M_2,...,T]\" alt=\"[S,...,M_1,...,M,...,M_2,...,T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a9f\/c02\/c1b\/a9fc02c1b83d6825156700b14d8d25d5.svg\" width=\"283\" height=\"22\"\/>. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1 <\/strong>\u0434\u043b\u044f \u043f\u0430\u0440 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/71c\/e80\/978\/71ce80978d893fa4a6739c6b907b8d87.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba7\/c8b\/2ad\/ba7c8b2ad191acb8da82eb542fff06de.svg\" width=\"27\" height=\"19\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bd1\/c86\/5be\/bd1c865bec968f1ac5999125d29e7674.svg\" width=\"27\" height=\"19\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c6\/8e0\/b33\/9c68e0b3352b0ebaac76d1574d3c7725.svg\" width=\"20\" height=\"17\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/533\/372\/be7\/533372be7083ff21ae4764dc37788ff0.svg\" width=\"20\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bbe\/118\/694\/bbe1186941772562cab7e30ff5fc6fd2.svg\" width=\"27\" height=\"19\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cfb\/aa2\/b05\/cfbaa2b05f57d7a269ac159d156df1d6.svg\" width=\"27\" height=\"19\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1bd\/bbe\/a79\/1bdbbea7954a1b519e514ac64124a5d1.svg\" width=\"14\" height=\"17\"\/>. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_3\" alt=\"M_3\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a8f\/73e\/ca3\/a8f73eca38def04c807b1e9b100a68c7.svg\" width=\"27\" height=\"20\"\/>\u0434\u043b\u044f \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/71c\/e80\/978\/71ce80978d893fa4a6739c6b907b8d87.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba7\/c8b\/2ad\/ba7c8b2ad191acb8da82eb542fff06de.svg\" width=\"27\" height=\"19\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_4\" alt=\"M_4\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e1\/f4e\/604\/9e1f4e604a95a9fcdb7b029ffee7834f.svg\" width=\"27\" height=\"19\"\/>\u0434\u043b\u044f \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_1\" alt=\"M_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d88\/f2e\/d07\/d88f2ed07742c279f72f6f67452eed38.svg\" width=\"27\" height=\"19\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f80\/df5\/7fd\/f80df57fd8a62b47182675092381b168.svg\" width=\"20\" height=\"17\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_5\" alt=\"M_5\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b6a\/0b1\/a4d\/b6a0b1a4deab6eb58bfae2d31fbcefb5.svg\" width=\"27\" height=\"20\"\/>\u0434\u043b\u044f \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1cb\/940\/b87\/1cb940b87e5a73bad0a0fd8249a6dab6.svg\" width=\"20\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a9\/67f\/06e\/5a967f06e21f96819bf1dea7f68bcabb.svg\" width=\"27\" height=\"19\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_6\" alt=\"M_6\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/823\/c2e\/521\/823c2e521214ce04d1c70607c9f10ea2.svg\" width=\"27\" height=\"20\"\/>\u0434\u043b\u044f \u043f\u0430\u0440\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_2\" alt=\"M_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eea\/bcc\/a23\/eeabcca239e31910cea9968561a6d4c8.svg\" width=\"27\" height=\"19\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1bc\/789\/2e6\/1bc7892e64b91ed8cf82f4fd9d9b70db.svg\" width=\"14\" height=\"17\"\/>.<\/p>\n<p><strong>5. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_3\" alt=\"M_3\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/936\/097\/961\/936097961c71081653f8b0ebdb1dbf1c.svg\" width=\"27\" height=\"20\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_4\" alt=\"M_4\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c28\/75c\/d4e\/c2875cd4efaddd75075c7c939b1e5693.svg\" width=\"27\" height=\"19\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_5\" alt=\"M_5\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/471\/7ab\/ef0\/4717abef006992fc4fa13688fecead3b.svg\" width=\"27\" height=\"20\"\/>,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_6\" alt=\"M_6\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42b\/00f\/ac2\/42b00fac28b7985549ba30c53ba7418a.svg\" width=\"27\" height=\"20\"\/>, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,...,M_3,...,M_1,...,M_4,...,M,...,M_5,...,M_2,...,M_6,...,T]\" alt=\"[S,...,M_3,...,M_1,...,M_4,...,M,...,M_5,...,M_2,...,M_6,...,T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6f4\/b42\/381\/6f4b423810fb64c52aab1ede2c215581.svg\" width=\"565\" height=\"22\"\/>. <br \/>\u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1 <\/strong>\u0434\u043b\u044f \u043f\u0430\u0440<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35b\/3b4\/8b0\/35b3b48b031644e76c88dcbd2c84adc5.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_3\" alt=\"M_3\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c1\/9bf\/b89\/4c19bfb8933ac6016b0f89a72120c023.svg\" width=\"27\" height=\"20\"\/>,&#8230;,<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_6\" alt=\"M_6\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ad\/a9e\/507\/4ada9e507d35ef4f45fd50d83a9f7a54.svg\" width=\"27\" height=\"20\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f2b\/ebd\/e7f\/f2bebde7fc0327cad4ac143369151fd9.svg\" width=\"14\" height=\"17\"\/>.<\/p>\n<p>\u0418 \u0442.\u0434. \u043f\u043e\u043a\u0430 <em><u>\u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435<\/u><\/em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M_i\" alt=\"M_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5aa\/6ff\/fa0\/5aa6fffa0b11d8720e58f4630ac605b3.svg\" width=\"25\" height=\"20\"\/>, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6b2\/7b0\/27a\/6b27b027a72beb6e25ad57da4566719c.svg\" width=\"10\" height=\"17\"\/>-\u043e\u043c \u0448\u0430\u0433\u0435, \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0440\u0430\u0432\u043d\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\varnothing\" alt=\"\\varnothing\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bca\/9de\/c04\/bca9dec04732a329bf8d940b8c0a453c.svg\" width=\"15\" height=\"15\"\/>.<\/p>\n<h3>\u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/h3>\n<p><strong>\u0428\u0430\u0433 0 <\/strong>(<em>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ac\/d02\/f48\/7acd02f48401bdc89cc4208b3d158b44.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/243\/952\/cfe\/243952cfe4c51527c9a74b4560bcc0ce.svg\" width=\"14\" height=\"17\"\/>)<\/em><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d4\/6c2\/7a5\/9d46c27a5c6b21fcc14a221e9eb32c8c.png\" alt=\"\" title=\"\" width=\"449\" height=\"413\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d4\/6c2\/7a5\/9d46c27a5c6b21fcc14a221e9eb32c8c.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.1* <\/strong>(<em>\u0415\u0441\u043b\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\\in TF\" alt=\"S\\in TF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c46\/191\/5c1\/c461915c102ec14fc4afb80988cf2a62.svg\" width=\"64\" height=\"17\"\/>\u0438\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\\in SF\" alt=\"T\\in SF\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/456\/dba\/769\/456dba7699759c25f7d7f5b442c3b109.svg\" width=\"64\" height=\"17\"\/><\/em>)<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/133\/f68\/452\/133f68452c85610f51120978b4b07db3.png\" width=\"432\" height=\"414\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/133\/f68\/452\/133f68452c85610f51120978b4b07db3.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.2* <\/strong>(<em>\u0415\u0441\u043b\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF\\cap TF\\neq\\varnothing\" alt=\"SF\\cap TF\\neq\\varnothing\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dba\/0cd\/9db\/dba0cd9db87d2bfecb00356982da4e9d.svg\" width=\"117\" height=\"21\"\/><\/em>) <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/724\/f1d\/ce9\/724f1dce991dc0a4909f72dea1675f12.png\" width=\"419\" height=\"413\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/724\/f1d\/ce9\/724f1dce991dc0a4909f72dea1675f12.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.3* <\/strong>(<em>\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0448\u0430\u0433\u0438 <\/em><strong><em>1*<\/em><\/strong><em> \u0438 <\/em><strong><em>2*<\/em><\/strong><em>, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <\/em><strong><em>1<\/em><\/strong>)<\/p>\n<p><strong>\u0428\u0430\u0433 1<\/strong><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/04a\/cb2\/2fc\/04acb22fc6a8f0e1a4220badd7400416.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" width=\"462\" height=\"505\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/04a\/cb2\/2fc\/04acb22fc6a8f0e1a4220badd7400416.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e6c\/002\/5f9\/e6c0025f95fbc46092a59e6b1d62671b.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" width=\"471\" height=\"505\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e6c\/002\/5f9\/e6c0025f95fbc46092a59e6b1d62671b.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 2<\/strong><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f90\/a02\/0c0\/f90a020c080e95dfc706541edc33b335.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 1\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 1\" width=\"455\" height=\"507\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f90\/a02\/0c0\/f90a020c080e95dfc706541edc33b335.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 1<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5b2\/6c8\/5b5\/5b26c85b55fd71615dc7688bbd538b61.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" width=\"470\" height=\"516\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b2\/6c8\/5b5\/5b26c85b55fd71615dc7688bbd538b61.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 2 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rightarrow\" alt=\"\\rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8cd\/9e6\/702\/8cd9e6702140631d4aa88c6b8b7523ba.svg\" width=\"19\" height=\"13\"\/>\u0428\u0430\u0433 1 <\/strong>(<em>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0441 \u0448\u0430\u0433\u0430 <\/em><strong><em>2<\/em><\/strong><em> \u043d\u0430 \u0448\u0430\u0433 <\/em><strong><em>1<\/em><\/strong>)<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0f3\/17a\/683\/0f317a683af599757617b375f54811d5.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" width=\"430\" height=\"703\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f3\/17a\/683\/0f317a683af599757617b375f54811d5.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d54\/357\/cf5\/d54357cf509da1ffe38a6bb08a484a4f.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3\" width=\"423\" height=\"716\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d54\/357\/cf5\/d54357cf509da1ffe38a6bb08a484a4f.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 3 <\/strong>(<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,...,M,...,T]\" alt=\"[S,...,M,...,T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4a8\/4b4\/c58\/4a84b4c58cfe4fad25d4d111ad24d471.svg\" width=\"143\" height=\"22\"\/><em>. \u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <\/em><strong><em>1<\/em><\/strong><em> \u0434\u043b\u044f \u043f\u0430\u0440<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b0c\/3f9\/fa5\/b0c3f9fa568d6a55d7248460e11d831f.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/846\/457\/45b\/84645745bb383259d055d2e7acfe869d.svg\" width=\"20\" height=\"17\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e76\/e28\/be6\/e76e28be67ed289e1e0fcac23634c336.svg\" width=\"20\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ace\/62c\/ae2\/ace62cae232837598c90307f8b0033f5.svg\" width=\"14\" height=\"17\"\/><\/em>)<\/p>\n<p><strong>\u041f\u0430\u0440\u0430<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/895\/16c\/51b\/89516c51b97738f4294c2090120fa21b.svg\" width=\"12\" height=\"17\"\/><strong>\u0438<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f4e\/48b\/9ef\/f4e48b9ef75e305939ebe844f24cace6.svg\" width=\"20\" height=\"17\"\/><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a5e\/1b8\/d16\/a5e1b8d16c6da000022c00099dd46c25.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" width=\"468\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a5e\/1b8\/d16\/a5e1b8d16c6da000022c00099dd46c25.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/706\/378\/940\/706378940a95f2c8b2f5020c7df6b66e.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4\" width=\"470\" height=\"493\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/706\/378\/940\/706378940a95f2c8b2f5020c7df6b66e.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4<\/figcaption><\/figure>\n<p><strong>\u041f\u0430\u0440\u0430<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/033\/686\/06b\/03368606b503dfd25a49e61b57a9501a.svg\" width=\"20\" height=\"17\"\/><strong>\u0438<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/09e\/30e\/da3\/09e30eda3123e841c7541b75b4891b3c.svg\" width=\"14\" height=\"17\"\/><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/718\/8bd\/c20\/7188bdc20f7c592bfc74df187f677cf2.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2\" width=\"474\" height=\"496\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/718\/8bd\/c20\/7188bdc20f7c592bfc74df187f677cf2.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c41\/b53\/ed3\/c41b53ed34d24549b2b61c365faee965.png\" alt=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4\" title=\"\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4\" width=\"474\" height=\"493\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c41\/b53\/ed3\/c41b53ed34d24549b2b61c365faee965.png\"\/><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4<\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f.<\/p>\n<h3>\u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0448\u0430\u0433\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/561\/d54\/754\/561d547548e1bb5da1ea771120077893.svg\" width=\"20\" height=\"17\"\/>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1d0\/6a5\/944\/1d06a5944518ff1599b0595868278eed.svg\" width=\"7\" height=\"16\"\/>-\u043e\u043c\u0443 \u0434\u0440\u0443\u0433\u0443 \u0438\u0437<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"TF(SF)\" alt=\"TF(SF)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c79\/f22\/116\/c79f22116152efea9cb2553670f5d2e3.svg\" width=\"70\" height=\"22\"\/>\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T_iF(S_iF)\" alt=\"T_iF(S_iF)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a39\/92b\/c1c\/a3992bc1ce7d2d08459cf46022974f0a.svg\" width=\"80\" height=\"22\"\/>\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"SF(TF)\" alt=\"SF(TF)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f41\/7bd\/baa\/f417bdbaa59427745c72a498e99b4385.svg\" width=\"70\" height=\"22\"\/>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/722\/255\/169\/722255169fe94e88c09d38be2f4cc1b6.svg\" width=\"20\" height=\"17\"\/>, \u043d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e <br \/><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ad2\/fa7\/9a4\/ad2fa79a4348a3d8ef9505434e3895db.svg\" width=\"7\" height=\"16\"\/>-\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0445\u043e\u0434\u0438\u043c <strong><u>2 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438<\/u><\/strong>, \u0442.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S, \u2026, M, \u2026, T]\" alt=\"[S, \u2026, M, \u2026, T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1b\/a50\/bea\/a1ba50bead5639f268b57edd1dadb515.svg\" width=\"143\" height=\"22\"\/>\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,\u2026, M, m, \u2026, T]\" alt=\"[S,\u2026, M, m, \u2026, T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a4a\/e92\/1b3\/a4ae921b355b6093b106b71610ed237d.svg\" width=\"168\" height=\"22\"\/>\u043b\u0438\u0431\u043e<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"[S,\u2026, m, M, \u2026, T]\" alt=\"[S,\u2026, m, M, \u2026, T]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a36\/a8b\/233\/a36a8b2333be54e9b7f04d8359cac209.svg\" width=\"168\" height=\"22\"\/>.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"M\" alt=\"M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a3a\/148\/5c3\/a3a1485c3595bcfc6d125a5948ec6cda.svg\" width=\"20\" height=\"17\"\/><\/p>\n<pre><code class=\"python\"># source \u0438 target - id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T # limit - \u0444\u043b\u0430\u0433 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u0440\u0443\u0437\u0435\u0439  def find_mutual_friend(source, target, limit=False): # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u0440\u0443\u0437\u0435\u0439     FRIENDS_COUNT = 100  if source == target: return None, None, None  if None in [source, target]: return None, None, None      # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S \u0438 T source_friends = get_friends(source) target_friends = get_friends(target)  if source in target_friends or target in source_friends: return None, None, None  mutual_friends = intersection(source_friends, target_friends) if mutual_friends: return None, None, mutual_friends[0]  source_friends = get_friends(source) if not limit else get_friends(source, count=FRIENDS_COUNT) target_friends = get_friends(target) if not limit else get_friends(target, count=FRIENDS_COUNT)  # 0 - \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f T # 1 - \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S i = 0 last_source_level = source_friends last_target_level = target_friends while True:         # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 SF \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S if i: next_source_level = []  for friend in last_source_level: friends = get_friends(friend, count=FRIENDS_COUNT) if not friends: continue mutual_friends = intersection(last_target_level, friends)  if mutual_friends: return i, friend, mutual_friends[0]  next_source_level = union(next_source_level, friends)  last_source_level = next_source_level i = 0 continue          # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 TF \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f T next_target_level = []  for friend in last_target_level: friends = get_friends(friend, count=FRIENDS_COUNT) if not friends: continue mutual_friends = intersection(last_source_level, friends)  if mutual_friends: return i, friend, mutual_friends[0]  next_target_level = union(next_target_level, friends)  last_target_level = next_target_level i = 1<\/code><\/pre>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"S\" alt=\"S\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d6\/78b\/de3\/5d678bde302952dd3c069edc71c88d78.svg\" width=\"12\" height=\"17\"\/>\u0438<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b1\/c90\/a74\/4b1c90a74a637825bace888b25cf5427.svg\" width=\"14\" height=\"17\"\/><\/strong><\/p>\n<pre><code class=\"python\"># source \u0438 target - id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T def create_chain(source, target):     # \u0428\u0430\u0433 0     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S \u0438 T source_friends = get_friends(source) target_friends = get_friends(target)      # \u0415\u0441\u043b\u0438 |TF| > |SF|, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T \u043c\u0435\u0441\u0442\u0430\u043c\u0438     # \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f T if len(target_friends) > len(source_friends): temp = source source = target target = temp      # \u041d\u0430\u0445\u043e\u0434\u0438\u043c M \u0438 m (\u043f\u0440\u043e \u044d\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0438)     # i - \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c m     # friend - m     # mutual_friend - M i, friend, mutual_friend = find_mutual_friend(source, target)      # \u0428\u0430\u0433 0.1     # \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 S \u0438 T \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0437\u044c\u044f\u043c\u0438  if mutual_friend is None: return [source, target]  chain = [source, mutual_friend, target]      # \u0428\u0430\u0433 0.2     # \u041d\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f m, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u043e\u0437\u0430\u0440\u0430\u0449\u0430\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 [S, M, T] if not friend: return chain      # \u0428\u0430\u0433 0.3     # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c chain = [source, friend, mutual_friend, target] if i else [source, mutual_friend, friend, target] while True: new_chain = [] new_mutual_friends = []          # \u041d\u0430\u0445\u043e\u0434\u0438\u043c M \u0438 m \u0434\u043b\u044f \u043f\u0430\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0443\u0436\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 for i in range(len(chain) - 1): j, friend, mutual_friend = find_mutual_friend(chain[i], chain[i + 1], limit=True)  new_mutual_friends.append(mutual_friend)              # \u0421\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 [S, M, T], \u043b\u0438\u0431\u043e [S, M, m, T], \u043b\u0438\u0431\u043e [S, m, M, T]  new_chain.append(chain[i]) if friend not in chain: if j: new_chain += [friend, mutual_friend] else: new_chain += [mutual_friend, friend] else: if mutual_friend: new_chain.append(mutual_friend)          # \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043d\u043e\u0432\u044b\u043c\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 chain = new_chain + [chain[-1]]          # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435 M \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f None if new_mutual_friends.count(None) == len(new_mutual_friends): break      # \u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 None \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0435     # None \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a M \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0437\u044c\u044f\u043c\u0438 return remove_None(chain)<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c, \u043d\u043e \u0435\u0433\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c. \u041e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u0442.\u043a. \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0445\u043e\u0442\u044f \u0431\u044b \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0434\u0440\u0443\u0437\u0435\u0439. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043b\u0438\u0448\u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a. <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430, \u0438 \u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.   <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/701380\/\"> https:\/\/habr.com\/ru\/post\/701380\/<\/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<h3>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h3>\n<p>\u0411\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c, \u044f \u0440\u0435\u0448\u0438\u043b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0443\u0440\u0441\u043e\u0432\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f \u0441\u043e\u0446\u0441\u0435\u0442\u0438. \u041c\u043d\u0435 \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c, \u043d\u0430\u0447\u0430\u043b \u043f\u043e\u0438\u0441\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/132558\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0442\u0435\u043e\u0440\u0438\u044f \u0448\u0435\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u043f\u043e\u0436\u0430\u0442\u0438\u0439<\/a>, \u0442\u0430\u043c \u0431\u044b\u043b\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0438\u0434\u0435\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B2%D1%83%D0%BD%D0%B0%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9_%D0%BF%D0%BE%D0%B8%D1%81%D0%BA\" rel=\"noopener noreferrer nofollow\">\u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430<\/a>, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0441\u0430\u043c\u044b\u043c \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<h3>\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p><strong><\/strong>(<em>source<\/em>) \u2014 <em>id<\/em> \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><\/strong>(<em>source friends<\/em>) \u2014 \u0441\u043f\u0438\u0441\u043e\u043a <em>id<\/em> \u0434\u0440\u0443\u0437\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><\/strong>(<em>target<\/em>) \u2014 <em>id<\/em> \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><\/strong>(<em>target friend<\/em>s) \u2014 \u0441\u043f\u0438\u0441\u043e\u043a <em>id<\/em> \u0434\u0440\u0443\u0437\u0435\u0439 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<br \/><strong><\/strong>(<em>mutual friend<\/em>) \u2014 \u0441\u0430\u043c\u044b\u0439 \u0434\u0430\u043b\u044c\u043d\u0438\u0439 \u043e\u0431\u0449\u0438\u0439 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439, \u0442.\u0435. \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <strong><\/strong>\u0434\u043e <strong><\/strong>\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 <strong><\/strong>\u0434\u043e <strong><\/strong><em><u>\u0440\u0430\u0432\u043d\u044b<\/u><\/em> \u043b\u0438\u0431\u043e <em><u>\u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 1<\/u><\/em><\/p>\n<h3>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p><strong>0.<\/strong>\u00a0\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f<strong><\/strong>\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:<br \/>  <strong><em>1*.<\/em><\/strong> \u0415\u0441\u043b\u0438\u0438\u043b\u0438, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443<br \/>  <strong><em>2*.<\/em><\/strong> \u0415\u0441\u043b\u0438, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u0433\u0434\u0435<strong><\/strong>\u2014 \u043b\u044e\u0431\u043e\u0435 <em>id<\/em> \u0438\u0437<br \/>  <strong><em>3*.<\/em><\/strong> \u0415\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e <strong><em>1*<\/em><\/strong> \u0438 <strong><em>2*<\/em><\/strong>, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>1<\/p>\n<p>1. <\/strong>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f, \u0442.\u0435. \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0433\u0434\u0435. \u0415\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e, \u0442\u043e\u0433\u0434\u0430 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>3<\/strong>, \u0438\u043d\u0430\u0447\u0435 <br \/>\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>2<\/p>\n<p>2. <\/strong>\u0418\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f, \u0442.\u0435. \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0433\u0434\u0435. \u0415\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e, \u0442\u043e\u0433\u0434\u0430 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>3<\/strong>, \u0438\u043d\u0430\u0447\u0435 <br \/>\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <strong>1<\/p>\n<p>3. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1<\/strong> \u0434\u043b\u044f \u043f\u0430\u0440\u0438,\u0438. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c\u0434\u043b\u044f  \u043f\u0430\u0440\u044b\u0438,\u0434\u043b\u044f \u043f\u0430\u0440\u044b\u0438.<\/p>\n<p><strong>4. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d\u044b\u0438, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1 <\/strong>\u0434\u043b\u044f \u043f\u0430\u0440 \u0438,\u0438,\u0438,\u0438. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u043b\u044f \u043f\u0430\u0440\u044b\u0438,\u0434\u043b\u044f \u043f\u0430\u0440\u044b\u0438,\u0434\u043b\u044f \u043f\u0430\u0440\u044b\u0438,\u0434\u043b\u044f \u043f\u0430\u0440\u044b\u0438.<\/p>\n<p><strong>5. <\/strong>\u041d\u0430\u0439\u0434\u0435\u043d\u044b ,,,, \u0442\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434 . <br \/>\u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <strong>1 <\/strong>\u0434\u043b\u044f \u043f\u0430\u0440\u0438,&#8230;,\u0438.<\/p>\n<p>\u0418 \u0442.\u0434. \u043f\u043e\u043a\u0430 <em><u>\u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435<\/u><\/em>, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 -\u043e\u043c \u0448\u0430\u0433\u0435, \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0440\u0430\u0432\u043d\u044b .<\/p>\n<h3>\u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/h3>\n<p><strong>\u0428\u0430\u0433 0 <\/strong>(<em>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f\u0438)<\/em><\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.1* <\/strong>(<em>\u0415\u0441\u043b\u0438\u0438\u043b\u0438 <\/em>)<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.2* <\/strong>(<em>\u0415\u0441\u043b\u0438 <\/em>) <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 0.3* <\/strong>(<em>\u041d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0448\u0430\u0433\u0438 <\/em><strong><em>1*<\/em><\/strong><em> \u0438 <\/em><strong><em>2*<\/em><\/strong><em>, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0448\u0430\u0433\u0443 <\/em><strong><em>1<\/em><\/strong>)<\/p>\n<p><strong>\u0428\u0430\u0433 1<\/strong><\/p>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 2<\/strong><\/p>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 1<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 2 \u0428\u0430\u0433 1 <\/strong>(<em>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0441 \u0448\u0430\u0433\u0430 <\/em><strong><em>2<\/em><\/strong><em> \u043d\u0430 \u0448\u0430\u0433 <\/em><strong><em>1<\/em><\/strong>)<\/p>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 3<\/figcaption><\/figure>\n<p><strong>\u0428\u0430\u0433 3 <\/strong>(<em>. \u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0430\u0433 <\/em><strong><em>1<\/em><\/strong><em> \u0434\u043b\u044f \u043f\u0430\u0440\u0438, \u0438<\/em>)<\/p>\n<p><strong>\u041f\u0430\u0440\u0430<\/strong><strong>\u0438<\/strong><\/p>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4<\/figcaption><\/figure>\n<p><strong>\u041f\u0430\u0440\u0430<\/strong><strong>\u0438<\/strong><\/p>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 2<\/figcaption><\/figure>\n<hr\/>\n<figure class=\"\"><figcaption>\u0421\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0448\u0430\u0433\u0443 4<\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f.<\/p>\n<h3>\u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0448\u0430\u0433\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e-\u043e\u043c\u0443 \u0434\u0440\u0443\u0433\u0443 \u0438\u0437\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e, \u043d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e <br \/>-\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0445\u043e\u0434\u0438\u043c <strong><u>2 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438<\/u><\/strong>, \u0442.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043b\u0438\u0431\u043e.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430<\/strong><\/p>\n<pre><code class=\"python\"># source \u0438 target - id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T # limit - \u0444\u043b\u0430\u0433 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u0440\u0443\u0437\u0435\u0439  def find_mutual_friend(source, target, limit=False): # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u0440\u0443\u0437\u0435\u0439     FRIENDS_COUNT = 100  if source == target: return None, None, None  if None in [source, target]: return None, None, None      # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S \u0438 T source_friends = get_friends(source) target_friends = get_friends(target)  if source in target_friends or target in source_friends: return None, None, None  mutual_friends = intersection(source_friends, target_friends) if mutual_friends: return None, None, mutual_friends[0]  source_friends = get_friends(source) if not limit else get_friends(source, count=FRIENDS_COUNT) target_friends = get_friends(target) if not limit else get_friends(target, count=FRIENDS_COUNT)  # 0 - \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f T # 1 - \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S i = 0 last_source_level = source_friends last_target_level = target_friends while True:         # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 SF \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S if i: next_source_level = []  for friend in last_source_level: friends = get_friends(friend, count=FRIENDS_COUNT) if not friends: continue mutual_friends = intersection(last_target_level, friends)  if mutual_friends: return i, friend, mutual_friends[0]  next_source_level = union(next_source_level, friends)  last_source_level = next_source_level i = 0 continue          # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 TF \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f T next_target_level = []  for friend in last_target_level: friends = get_friends(friend, count=FRIENDS_COUNT) if not friends: continue mutual_friends = intersection(last_source_level, friends)  if mutual_friends: return i, friend, mutual_friends[0]  next_target_level = union(next_target_level, friends)  last_target_level = next_target_level i = 1<\/code><\/pre>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f\u0438<\/strong><\/p>\n<pre><code class=\"python\"># source \u0438 target - id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T def create_chain(source, target):     # \u0428\u0430\u0433 0     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u0440\u0443\u0437\u0435\u0439 \u0434\u043b\u044f S \u0438 T source_friends = get_friends(source) target_friends = get_friends(target)      # \u0415\u0441\u043b\u0438 |TF| > |SF|, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 S \u0438 T \u043c\u0435\u0441\u0442\u0430\u043c\u0438     # \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u043f\u043e\u0438\u0441\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f T if len(target_friends) > len(source_friends): temp = source source = target target = temp      # \u041d\u0430\u0445\u043e\u0434\u0438\u043c M \u0438 m (\u043f\u0440\u043e \u044d\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0438)     # i - \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c m     # friend - m     # mutual_friend - M i, friend, mutual_friend = find_mutual_friend(source, target)      # \u0428\u0430\u0433 0.1     # \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 S \u0438 T \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0437\u044c\u044f\u043c\u0438  if mutual_friend is None: return [source, target]  chain = [source, mutual_friend, target]      # \u0428\u0430\u0433 0.2     # \u041d\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f m, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u043e\u0437\u0430\u0440\u0430\u0449\u0430\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 [S, M, T] if not friend: return chain      # \u0428\u0430\u0433 0.3     # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c chain = [source, friend, mutual_friend, target] if i else [source, mutual_friend, friend, target] while True: new_chain = [] new_mutual_friends = []          # \u041d\u0430\u0445\u043e\u0434\u0438\u043c M \u0438 m \u0434\u043b\u044f \u043f\u0430\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0443\u0436\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 for i in range(len(chain) - 1): j, friend, mutual_friend = find_mutual_friend(chain[i], chain[i + 1], limit=True)  new_mutual_friends.append(mutual_friend)              # \u0421\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 [S, M, T], \u043b\u0438\u0431\u043e [S, M, m, T], \u043b\u0438\u0431\u043e [S, m, M, T]  new_chain.append(chain[i]) if friend not in chain: if j: new_chain += [friend, mutual_friend] else: new_chain += [mutual_friend, friend] else: if mutual_friend: new_chain.append(mutual_friend)          # \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043d\u043e\u0432\u044b\u043c\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 chain = new_chain + [chain[-1]]          # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435 M \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f None if new_mutual_friends.count(None) == len(new_mutual_friends): break      # \u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 None \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0435     # None \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a M \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0437\u044c\u044f\u043c\u0438 return remove_None(chain)<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c, \u043d\u043e \u0435\u0433\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c. \u041e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u0442.\u043a. \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0445\u043e\u0442\u044f \u0431\u044b \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0434\u0440\u0443\u0437\u0435\u0439. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043b\u0438\u0448\u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a. <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430, \u0438 \u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.   <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/701380\/\"> https:\/\/habr.com\/ru\/post\/701380\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-341662","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341662","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=341662"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341662\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}