{"id":328429,"date":"2022-01-23T03:00:10","date_gmt":"2022-01-23T03:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=328429"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=328429","title":{"rendered":"<span>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430 \u043d\u0430 \u0421#<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b:<\/p>\n<ol>\n<li>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 List&lt;><\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u0435\u0441\u0443<\/p>\n<\/li>\n<li>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0433\u0440\u0430\u0444\u0430. <\/p>\n<details class=\"spoiler\">\n<summary>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0432\u044b \u043d\u0435\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0442\u043e \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c <s>\u043f\u0430\u0440\u0443 \u043a\u043d\u0438\u0433 \u043f\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432<\/s>  \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"342\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c08\/d9e\/aa1\/c08d9eaa1acee96b8fe8ec6b30095760.png\" data-width=\"1168\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0441\u0435 \u0435\u0433\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <abbr title=\"\u0426\u0438\u043a\u043b\u043e\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0443\u0442\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0435\u0440\u0432\u0430\u044f \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.\">\u0446\u0438\u043a\u043b\u043e\u0432<\/abbr>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0441\u0442\u043e\u0432\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0446\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0430\u0445.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u0435\u043b\u0438\u043c \u0440\u0451\u0431\u0440\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0432\u0435\u0441\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"346\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/041\/93a\/6d9\/04193a6d9e9911854837527940a62bc9.png\" data-width=\"772\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0440\u0435\u0447\u044c \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u0435 \u0433\u0440\u0430\u0444\u0430. \u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0441\u0442\u043e\u0432\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0442\u043e, \u0441\u0443\u043c\u043c\u0430 \u0432\u0435\u0441\u0430 \u0432\u0441\u0435\u0445 \u0440\u0451\u0431\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445.  <\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0441\u0442\u0440\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0439, \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0443<\/a> \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u043e\u043b\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438.<\/p>\n<h2>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h2>\n<ol>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0440\u0451\u0431\u0440\u0430 \u043f\u043e \u0432\u0435\u0441\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0431\u0440\u043e. <\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u0438\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0446\u0438\u043a\u043b &#8212; \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c. <\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440 \u0438 \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430. \u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0432\u0435\u0441\u0451\u043b\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0438\u0437 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f &#8212; \u0442\u0440\u0435\u0442\u0438\u0439. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0438\u043a\u043b\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0437\u0430\u043d\u044f\u0442\u0438\u0435\u043c. \u0415\u0433\u043e \u043c\u044b \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. <\/p>\n<p>\u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c List&lt;>. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0440\u043e\u043c\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445, \u0432<a href=\"https:\/\/github.com\/Arctic-beaver\/MinimumBackbone\" rel=\"noopener noreferrer nofollow\"> \u044d\u0442\u043e\u043c<\/a> \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u043d\u0443\u0436\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0421\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432 \u043d\u0435\u0439 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. <\/p>\n<h2>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430<\/h2>\n<p>\u0427\u0442\u043e \u0435\u0441\u0442\u044c \u0433\u0440\u0430\u0444? \u041f\u043e \u0441\u0443\u0442\u0438 &#8212; \u0441\u043e\u0432\u043e\u043a\u0443\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0445 \u0438\u0445 \u0440\u0451\u0431\u0435\u0440. \u041d\u043e \u0432\u0435\u0434\u044c \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u0435\u0441\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e \u043a\u0430\u0436\u0434\u043e\u043c \u0440\u0435\u0431\u0440\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043e\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442, \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u0440\u0451\u0431\u0435\u0440, \u0432 \u043d\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445.<\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u0440\u0430\u0444 \u0432 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a \u043b\u0438\u0441\u0442\u043e\u043c \u0440\u0451\u0431\u0435\u0440. <\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0431\u0440\u0430 \u0438 IComparable<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0440\u0435\u0431\u0440\u0430: \u0432\u0441\u0451 \u0442\u043e, \u043e \u0447\u0451\u043c \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435. \u0412\u0435\u0441 \u0438 \u0434\u0432\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. <\/p>\n<pre><code class=\"cs\">    public class Edge : IComparable&lt;Edge>     {         public int EdgeWeight { get; set; }         public string VertexA { get; set; }         public string VertexB { get; set; }          public Edge(string vertexA, string vertexB, int weight)         {             VertexA = vertexA;             VertexB = vertexB;             EdgeWeight = weight;         }          public int CompareTo(Edge other)         {             if (other == null) return 1;             return EdgeWeight.CompareTo(other.EdgeWeight);         }     }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IComparable \u0441 \u0446\u0435\u043b\u044c\u044e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0438\u0441\u0442\u0430. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\/blob\/main\/LogicClasses\/Graph.cs\" rel=\"noopener noreferrer nofollow\">Graph<\/a>.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 Graph<\/h3>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442  IEnumerable&lt;Edge>. <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class Graph : IEnumerable&lt;Edge> {     \/\/\u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430     public IEnumerator&lt;Edge> GetEnumerator()     {         return _graph.GetEnumerator();     }      IEnumerator IEnumerable.GetEnumerator()     {         return _graph.GetEnumerator();     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043b\u0435\u0436\u0438\u0442 List&lt;Edge>, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0451\u0431\u0435\u0440. <\/p>\n<pre><code class=\"cs\">private List&lt;Edge> _graph;  public Graph() {       _graph = new List&lt;Edge>(); }  public Graph(Edge val) {      Edge[] value = new Edge[] { val };       _graph = new List&lt;Edge>(value); }<\/code><\/pre>\n<p>\u0414\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <abbr title=\"Add(Edge edge)\">\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0433\u0440\u0430\u0444\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0431\u0440\u0430<\/abbr> \u0438 \u0441<abbr title=\"Add(Graph graph)\">\u043b\u0438\u044f\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u043e\u0432<\/abbr>. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0446\u0438\u043a\u043b foreach (\u0434\u0430-\u0434\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 IEnumerable&lt;Edge>) \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0451\u0431\u0440\u0430\u043c \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445 \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443. <\/p>\n<pre><code class=\"cs\">public void Add(Graph graph) {       foreach (Edge edge in graph)       {            _graph.Add(edge);       } }  public void Add(Edge edge) {      _graph.Add(edge); }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u0430, \u043d\u043e \u0431\u0435\u0437 \u043d\u0435\u0451 \u043d\u0438\u043a\u0443\u0434\u0430. <\/p>\n<p><em>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/em> <\/p>\n<pre><code class=\"cs\">public int GetWeight() { int weight = 0;       foreach (Edge edge in _graph)       {            weight += edge.EdgeWeight;          }       return weight; } <\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>GetWeight()<\/code> \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430 \u0433\u0440\u0430\u0444\u0430. <\/p>\n<pre><code class=\"cs\">public override string ToString() {       string result = string.Empty;        foreach (Edge edge in _graph)       {            result += $\"{edge.VertexA} {edge.VertexB} {edge.EdgeWeight}\\n\";       }        return result; }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 ToString() \u043c\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 Graph \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f. <\/p>\n<h3>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u0435\u0441\u0443.<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437. \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0440\u0451\u0431\u0435\u0440 \u043f\u043e \u0432\u0435\u0441\u0443 &#8212; \u044d\u0442\u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438.<\/p>\n<pre><code class=\"cs\">public void Sort() {      _graph.Sort(); }<\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0440\u0451\u0431\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 IComparable. <\/p>\n<h2>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043b\u0451\u043a \u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u043c Set \u0441<strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0433\u0440\u0430\u0444\u043e\u043c<\/strong> \u0438 <strong>\u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0432\u0435\u0440\u0448\u0438\u043d<\/strong>, \u0432 \u043e\u043d\u044b\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445. <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0433\u0440\u0430\u0444 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:  \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e: 5-4 \u0432\u0435\u0441\u0430 4.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u044b 5 \u0438 4, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.   \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f: 4-3 \u0432\u0435\u0441\u0430 5.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u0443 3 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0412\u0435\u0440\u0448\u0438\u043d\u0430 4 \u0443\u0436\u0435 \u0442\u0430\u043c \u0431\u044b\u043b\u0430.  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445. \" title=\"\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0433\u0440\u0430\u0444 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:  \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e: 5-4 \u0432\u0435\u0441\u0430 4.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u044b 5 \u0438 4, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.   \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f: 4-3 \u0432\u0435\u0441\u0430 5.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u0443 3 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0412\u0435\u0440\u0448\u0438\u043d\u0430 4 \u0443\u0436\u0435 \u0442\u0430\u043c \u0431\u044b\u043b\u0430.  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445. \" height=\"403\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30d\/a23\/528\/30da23528597b0c1da05788b6e6aab3e.png\" data-width=\"989\"\/><figcaption>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0433\u0440\u0430\u0444 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:  \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e: 5-4 \u0432\u0435\u0441\u0430 4.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u044b 5 \u0438 4, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.   \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f: 4-3 \u0432\u0435\u0441\u0430 5.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u0443 3 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0412\u0435\u0440\u0448\u0438\u043d\u0430 4 \u0443\u0436\u0435 \u0442\u0430\u043c \u0431\u044b\u043b\u0430.  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445. <\/figcaption><\/figure>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043d\u0443\u0436\u0435\u043d \u043d\u0430\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0446\u0438\u043a\u043b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. <\/p>\n<p>\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0451\u043c \u0432 \u043a\u043e\u0434 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435:<\/p>\n<pre><code class=\"cs\"> public class Set  {         public Graph SetGraph;         public List&lt;string> Vertices;          public Set(Edge edge)         {             SetGraph = new Graph(edge);              Vertices = new List&lt;string>();             Vertices.Add(edge.VertexA);             Vertices.Add(edge.VertexB);         }    \/\/\u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430  }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><abbr title=\"public void Union(Set set, Edge connectingEdge)\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/abbr> \u0434\u0432\u0443\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0441\u043b\u0438\u044f\u043d\u0438\u0435. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043a \u0438\u043c\u0435\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0431\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><abbr title=\"public void AddEdge(Edge edge)\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/abbr> \u0440\u0435\u0431\u0440\u0430 \u043a \u0438\u043c\u0435\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443. <\/p>\n<\/li>\n<li>\n<p><abbr title=\"public bool Contains(string vertex)\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <\/abbr>\u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <code>Vertices.<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cs\">public void Union(Set set, Edge connectingEdge) {       SetGraph.Add(set.SetGraph);       Vertices.AddRange(set.Vertices);       SetGraph.Add(connectingEdge); }  public void AddEdge(Edge edge) {       SetGraph.Add(edge);       Vertices.Add(edge.VertexA);       Vertices.Add(edge.VertexB); }  public bool Contains(string vertex) {       return Vertices.Contains(vertex); }<\/code><\/pre>\n<h3>\u041a\u043b\u0430\u0441\u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u043c\u0435\u0441\u0442\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u043e\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0439 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0431\u0440\u043e \u0432 \u043e\u0434\u043d\u043e \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438\u043b\u0438 \u0440\u0435\u0448\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0439\u043c\u0451\u0442 \u0432 \u043d\u0438\u0445 \u0441\u0432\u043e\u0451 \u043c\u0435\u0441\u0442\u043e. <\/p>\n<pre><code class=\"cs\">class SystemOfDisjointSets     {         public List&lt;Set> Sets;          public void AddEdgeInSet(Edge edge)         {             \/\/\u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u043d\u0430\u0439\u0434\u0451\u0442 \u0441\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432            \/\/\u0438\u043b\u0438 \u043d\u0435 \u0432\u043e\u0439\u0434\u0451\u0442 \u0432 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.         }          public Set Find(string vertex)         {             foreach (Set set in Sets)             {                 if (set.Contains(vertex)) return set;             }             return null;         }     }<\/code><\/pre>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 Find<\/strong> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0433\u0440\u0430\u0444\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442, \u0438\u043b\u0438 null, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void AddEdgeInSet(Edge edge).<\/code><\/p>\n<h3>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>\u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0451\u0431\u0440\u0430\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043b\u0438 \u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u043c\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443. \u0414\u0430\u043b\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043b\u0443\u0447\u0430\u044f. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0438\u0445 \u043d\u0430 \u0441\u0445\u0435\u043c\u0435: <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"SetA - \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0410,  SetB - \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 B.  + - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443,  null - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443.\" title=\"SetA - \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0410,  SetB - \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 B.  + - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443,  null - \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443.\" height=\"532\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f24\/c0d\/3d4\/f24c0d3d43262f95e38d3994a6ffa446.png\" data-width=\"1054\"\/><figcaption>SetA &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0410,  SetB &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 B.  + &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443,  null &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443.<\/figcaption><\/figure>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043d\u0430 \u0421#:<\/p>\n<pre><code class=\"cs\">public void AddEdgeInSet(Edge edge) {       Set setA = Find(edge.VertexA);       Set setB = Find(edge.VertexB);        if (setA != null &amp;&amp; setB == null)       {            setA.AddEdge(edge);       }       else if (setA == null &amp;&amp; setB != null)       {           setB.AddEdge(edge);       }       else if (setA == null &amp;&amp; setB == null)       {            Set set = new Set(edge);            Sets.Add(set);       }       else if (setA != null &amp;&amp; setB != null)       {            if (setA != setB)            {                 setA.Union(setB, edge);                 Sets.Remove(setB);            }       } }<\/code><\/pre>\n<h2>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430: \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441 \u0447\u0438\u0441\u0442\u043e\u0439 \u0441\u043e\u0432\u0435\u0441\u0442\u044c\u044e \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Graph \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 FindMinimumSpanningTree. <\/p>\n<p>\u0412\u0441\u0451 \u043f\u043e \u043f\u0443\u043d\u043a\u0442\u0430\u043c, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u043d\u0430\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0451\u0431\u0440\u0430 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0432\u0435\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u0444 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d Set. \u041e\u043d \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0433\u0440\u0430\u0444 \u0431\u044b\u043b \u0441\u0432\u044f\u0437\u043d\u044b\u0439. <\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u043e\u043d\u043e \u0436\u0435 &#8212; \u0433\u0440\u0430\u0444 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0441\u0435\u0442\u0430. (\u0414\u043b\u044f Find &#8212; using System.LINQ)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cs\">public Graph FindMinimumSpanningTree() {      Sort();      var disjointSets = new SystemOfDisjointSets();      foreach (Edge edge in _graph)      {           disjointSets.AddEdgeInSet(edge);      }       return disjointSets.Sets.First().SetGraph; }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u0432 <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043a \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0434\u043b\u0438\u043d\u044f\u0442\u044c \u0438 \u0431\u0435\u0437 \u0442\u043e\u0433\u043e \u043e\u0431\u0451\u043c\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439.<\/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\/647189\/\"> https:\/\/habr.com\/ru\/post\/647189\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b:<\/p>\n<ol>\n<li>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 List&lt;><\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u0435\u0441\u0443<\/p>\n<\/li>\n<li>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0433\u0440\u0430\u0444\u0430. <\/p>\n<details class=\"spoiler\">\n<summary>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0432\u044b \u043d\u0435\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0442\u043e \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c <s>\u043f\u0430\u0440\u0443 \u043a\u043d\u0438\u0433 \u043f\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432<\/s>  \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0441\u0435 \u0435\u0433\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <abbr title=\"\u0426\u0438\u043a\u043b\u043e\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0443\u0442\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0435\u0440\u0432\u0430\u044f \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.\">\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.&#187;>\u0446\u0438\u043a\u043b\u043e\u0432<\/abbr>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0441\u0442\u043e\u0432\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0446\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0430\u0445.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u0435\u043b\u0438\u043c \u0440\u0451\u0431\u0440\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0432\u0435\u0441\u043e\u043c.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0440\u0435\u0447\u044c \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u0435 \u0433\u0440\u0430\u0444\u0430. \u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0441\u0442\u043e\u0432\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0442\u043e, \u0441\u0443\u043c\u043c\u0430 \u0432\u0435\u0441\u0430 \u0432\u0441\u0435\u0445 \u0440\u0451\u0431\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445.  <\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0441\u0442\u0440\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0439, \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0443<\/a> \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u043e\u043b\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438.<\/p>\n<h2>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h2>\n<ol>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0440\u0451\u0431\u0440\u0430 \u043f\u043e \u0432\u0435\u0441\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0431\u0440\u043e. <\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0432 \u0438\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0446\u0438\u043a\u043b &#8212; \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c. <\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0451\u0431\u0435\u0440 \u0438 \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430. \u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0432\u0435\u0441\u0451\u043b\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0438\u0437 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f &#8212; \u0442\u0440\u0435\u0442\u0438\u0439. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0438\u043a\u043b\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0437\u0430\u043d\u044f\u0442\u0438\u0435\u043c. \u0415\u0433\u043e \u043c\u044b \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. <\/p>\n<p>\u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c List&lt;>. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0440\u043e\u043c\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445, \u0432<a href=\"https:\/\/github.com\/Arctic-beaver\/MinimumBackbone\" rel=\"noopener noreferrer nofollow\"> \u044d\u0442\u043e\u043c<\/a> \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u043d\u0443\u0436\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0421\u0430\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432 \u043d\u0435\u0439 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. <\/p>\n<h2>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430<\/h2>\n<p>\u0427\u0442\u043e \u0435\u0441\u0442\u044c \u0433\u0440\u0430\u0444? \u041f\u043e \u0441\u0443\u0442\u0438 &#8212; \u0441\u043e\u0432\u043e\u043a\u0443\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0445 \u0438\u0445 \u0440\u0451\u0431\u0435\u0440. \u041d\u043e \u0432\u0435\u0434\u044c \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u0435\u0441\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e \u043a\u0430\u0436\u0434\u043e\u043c \u0440\u0435\u0431\u0440\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043e\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442, \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u0440\u0451\u0431\u0435\u0440, \u0432 \u043d\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445.<\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u0440\u0430\u0444 \u0432 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a \u043b\u0438\u0441\u0442\u043e\u043c \u0440\u0451\u0431\u0435\u0440. <\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0431\u0440\u0430 \u0438 IComparable<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0440\u0435\u0431\u0440\u0430: \u0432\u0441\u0451 \u0442\u043e, \u043e \u0447\u0451\u043c \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435. \u0412\u0435\u0441 \u0438 \u0434\u0432\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. <\/p>\n<pre><code class=\"cs\">    public class Edge : IComparable&lt;Edge>     {         public int EdgeWeight { get; set; }         public string VertexA { get; set; }         public string VertexB { get; set; }          public Edge(string vertexA, string vertexB, int weight)         {             VertexA = vertexA;             VertexB = vertexB;             EdgeWeight = weight;         }          public int CompareTo(Edge other)         {             if (other == null) return 1;             return EdgeWeight.CompareTo(other.EdgeWeight);         }     }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IComparable \u0441 \u0446\u0435\u043b\u044c\u044e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043b\u0438\u0441\u0442\u0430. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\/blob\/main\/LogicClasses\/Graph.cs\" rel=\"noopener noreferrer nofollow\">Graph<\/a>.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 Graph<\/h3>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442  IEnumerable&lt;Edge>. <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class Graph : IEnumerable&lt;Edge> {     \/\/\u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430     public IEnumerator&lt;Edge> GetEnumerator()     {         return _graph.GetEnumerator();     }      IEnumerator IEnumerable.GetEnumerator()     {         return _graph.GetEnumerator();     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043b\u0435\u0436\u0438\u0442 List&lt;Edge>, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0451\u0431\u0435\u0440. <\/p>\n<pre><code class=\"cs\">private List&lt;Edge> _graph;  public Graph() {       _graph = new List&lt;Edge>(); }  public Graph(Edge val) {      Edge[] value = new Edge[] { val };       _graph = new List&lt;Edge>(value); }<\/code><\/pre>\n<p>\u0414\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <abbr title=\"Add(Edge edge)\">\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0433\u0440\u0430\u0444\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0431\u0440\u0430<\/abbr> \u0438 \u0441<abbr title=\"Add(Graph graph)\">\u043b\u0438\u044f\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u043e\u0432<\/abbr>. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0446\u0438\u043a\u043b foreach (\u0434\u0430-\u0434\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 IEnumerable&lt;Edge>) \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0451\u0431\u0440\u0430\u043c \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445 \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443. <\/p>\n<pre><code class=\"cs\">public void Add(Graph graph) {       foreach (Edge edge in graph)       {            _graph.Add(edge);       } }  public void Add(Edge edge) {      _graph.Add(edge); }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u0430, \u043d\u043e \u0431\u0435\u0437 \u043d\u0435\u0451 \u043d\u0438\u043a\u0443\u0434\u0430. <\/p>\n<p><em>\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/em> <\/p>\n<pre><code class=\"cs\">public int GetWeight() { int weight = 0;       foreach (Edge edge in _graph)       {            weight += edge.EdgeWeight;          }       return weight; } <\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>GetWeight()<\/code> \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430 \u0433\u0440\u0430\u0444\u0430. <\/p>\n<pre><code class=\"cs\">public override string ToString() {       string result = string.Empty;        foreach (Edge edge in _graph)       {            result += $\"{edge.VertexA} {edge.VertexB} {edge.EdgeWeight}\\n\";       }        return result; }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 ToString() \u043c\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 Graph \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f. <\/p>\n<h3>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0451\u0431\u0435\u0440 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u0435\u0441\u0443.<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437. \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0440\u0451\u0431\u0435\u0440 \u043f\u043e \u0432\u0435\u0441\u0443 &#8212; \u044d\u0442\u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438.<\/p>\n<pre><code class=\"cs\">public void Sort() {      _graph.Sort(); }<\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0440\u0451\u0431\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 IComparable. <\/p>\n<h2>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043b\u0451\u043a \u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f.<\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u043c Set \u0441<strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0433\u0440\u0430\u0444\u043e\u043c<\/strong> \u0438 <strong>\u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0432\u0435\u0440\u0448\u0438\u043d<\/strong>, \u0432 \u043e\u043d\u044b\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445. <\/p>\n<figure class=\"full-width\"><figcaption>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0433\u0440\u0430\u0444 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:  \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e: 5-4 \u0432\u0435\u0441\u0430 4.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u044b 5 \u0438 4, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.   \u0412\u044b\u0431\u0440\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f: 4-3 \u0432\u0435\u0441\u0430 5.  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0433\u0440\u0430\u0444 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.  \u0412\u0435\u0440\u0448\u0438\u043d\u0443 3 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0412\u0435\u0440\u0448\u0438\u043d\u0430 4 \u0443\u0436\u0435 \u0442\u0430\u043c \u0431\u044b\u043b\u0430.  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445. <\/figcaption><\/figure>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u0438\u0441\u0442 \u0432\u0435\u0440\u0448\u0438\u043d \u043d\u0443\u0436\u0435\u043d \u043d\u0430\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0446\u0438\u043a\u043b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. <\/p>\n<p>\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0451\u043c \u0432 \u043a\u043e\u0434 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435:<\/p>\n<pre><code class=\"cs\"> public class Set  {         public Graph SetGraph;         public List&lt;string> Vertices;          public Set(Edge edge)         {             SetGraph = new Graph(edge);              Vertices = new List&lt;string>();             Vertices.Add(edge.VertexA);             Vertices.Add(edge.VertexB);         }    \/\/\u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430  }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><abbr title=\"public void Union(Set set, Edge connectingEdge)\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/abbr> \u0434\u0432\u0443\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0441\u043b\u0438\u044f\u043d\u0438\u0435. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043a \u0438\u043c\u0435\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0431\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><abbr title=\"public void AddEdge(Edge edge)\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/abbr> \u0440\u0435\u0431\u0440\u0430 \u043a \u0438\u043c\u0435\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443. <\/p>\n<\/li>\n<li>\n<p><abbr title=\"public bool Contains(string vertex)\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <\/abbr>\u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <code>Vertices.<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cs\">public void Union(Set set, Edge connectingEdge) {       SetGraph.Add(set.SetGraph);       Vertices.AddRange(set.Vertices);       SetGraph.Add(connectingEdge); }  public void AddEdge(Edge edge) {       SetGraph.Add(edge);       Vertices.Add(edge.VertexA);       Vertices.Add(edge.VertexB); }  public bool Contains(string vertex) {       return Vertices.Contains(vertex); }<\/code><\/pre>\n<h3>\u041a\u043b\u0430\u0441\u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u043c\u0435\u0441\u0442\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u043e\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0439 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0431\u0440\u043e \u0432 \u043e\u0434\u043d\u043e \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438\u043b\u0438 \u0440\u0435\u0448\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0439\u043c\u0451\u0442 \u0432 \u043d\u0438\u0445 \u0441\u0432\u043e\u0451 \u043c\u0435\u0441\u0442\u043e. <\/p>\n<pre><code class=\"cs\">class SystemOfDisjointSets     {         public List&lt;Set> Sets;          public void AddEdgeInSet(Edge edge)         {             \/\/\u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0431\u0440\u043e \u043d\u0430\u0439\u0434\u0451\u0442 \u0441\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432            \/\/\u0438\u043b\u0438 \u043d\u0435 \u0432\u043e\u0439\u0434\u0451\u0442 \u0432 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e.         }          public Set Find(string vertex)         {             foreach (Set set in Sets)             {                 if (set.Contains(vertex)) return set;             }             return null;         }     }<\/code><\/pre>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 Find<\/strong> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0433\u0440\u0430\u0444\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442, \u0438\u043b\u0438 null, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void AddEdgeInSet(Edge edge).<\/code><\/p>\n<h3>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>\u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0440\u0451\u0431\u0440\u0430\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043b\u0438 \u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u043c\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443. \u0414\u0430\u043b\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043b\u0443\u0447\u0430\u044f. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0438\u0445 \u043d\u0430 \u0441\u0445\u0435\u043c\u0435: <\/p>\n<figure class=\"full-width\"><figcaption>SetA &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u0410,  SetB &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u0430 B.  + &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443,  null &#8212; \u0432\u0435\u0440\u0448\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443.<\/figcaption><\/figure>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043d\u0430 \u0421#:<\/p>\n<pre><code class=\"cs\">public void AddEdgeInSet(Edge edge) {       Set setA = Find(edge.VertexA);       Set setB = Find(edge.VertexB);        if (setA != null &amp;&amp; setB == null)       {            setA.AddEdge(edge);       }       else if (setA == null &amp;&amp; setB != null)       {           setB.AddEdge(edge);       }       else if (setA == null &amp;&amp; setB == null)       {            Set set = new Set(edge);            Sets.Add(set);       }       else if (setA != null &amp;&amp; setB != null)       {            if (setA != setB)            {                 setA.Union(setB, edge);                 Sets.Remove(setB);            }       } }<\/code><\/pre>\n<h2>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430: \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441 \u0447\u0438\u0441\u0442\u043e\u0439 \u0441\u043e\u0432\u0435\u0441\u0442\u044c\u044e \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a\u0440\u0430\u0441\u043a\u0430\u043b\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Graph \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 FindMinimumSpanningTree. <\/p>\n<p>\u0412\u0441\u0451 \u043f\u043e \u043f\u0443\u043d\u043a\u0442\u0430\u043c, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u043d\u0430\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0451\u0431\u0440\u0430 \u0433\u0440\u0430\u0444\u0430 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0432\u0435\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0430\u0444 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d Set. \u041e\u043d \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0433\u0440\u0430\u0444 \u0431\u044b\u043b \u0441\u0432\u044f\u0437\u043d\u044b\u0439. <\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u043e\u0432\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e, \u043e\u043d\u043e \u0436\u0435 &#8212; \u0433\u0440\u0430\u0444 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0441\u0435\u0442\u0430. (\u0414\u043b\u044f Find &#8212; using System.LINQ)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"cs\">public Graph FindMinimumSpanningTree() {      Sort();      var disjointSets = new SystemOfDisjointSets();      foreach (Edge edge in _graph)      {           disjointSets.AddEdgeInSet(edge);      }       return disjointSets.Sets.First().SetGraph; }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u0432 <a href=\"https:\/\/github.com\/Arctic-beaver\/KraskalsAlgorithm\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0430 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043a \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0434\u043b\u0438\u043d\u044f\u0442\u044c \u0438 \u0431\u0435\u0437 \u0442\u043e\u0433\u043e \u043e\u0431\u0451\u043c\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-328429","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328429","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=328429"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328429\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}