{"id":2647,"date":"2017-07-04T23:10:54","date_gmt":"2017-07-04T20:10:54","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=2647"},"modified":"2017-07-05T23:09:08","modified_gmt":"2017-07-05T20:09:08","slug":"e-olymp-975-%d1%84%d0%bb%d0%be%d0%b9%d0%b4","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=2647","title":{"rendered":"e-olymp 975. \u0424\u043b\u043e\u0439\u0434"},"content":{"rendered":"<h3><strong>\u0417\u0430\u0434\u0430\u0447\u0430<\/strong><\/h3>\n<p>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/975\">e-olymp<\/a>.<\/p>\n<p>\u0414\u0430\u043d \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444. \u041d\u0430\u0439\u0442\u0438 \u043f\u0430\u0440\u0443 \u0432\u0435\u0440\u0448\u0438\u043d, \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440 \u0432\u0435\u0440\u0448\u0438\u043d.<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0433\u0440\u0430\u0444\u0430 [latex]n[\/latex] [latex](1 \\leq n \\leq 100)[\/latex]. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 [latex]n[\/latex]<b>\u00a0<\/b>\u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e [latex]n[\/latex] \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0434\u0430\u044e\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441\u043c\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0430. \u0412 \u043d\u0435\u0439\u00a0-1\u00a0\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0435\u0431\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438, \u0430 \u043b\u044e\u0431\u043e\u0435 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &#8212; \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0435\u0431\u0440\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430. \u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0443\u043b\u0438.<\/p>\n<p><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/p>\n<p>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<h3><strong>\u0422\u0435\u0441\u0442\u044b<\/strong><\/h3>\n<table style=\"height: 102px;width: 392px\">\n<tbody>\n<tr>\n<td style=\"width: 24px;text-align: center\">\u2116<\/td>\n<td style=\"width: 52px;text-align: center\">n<\/td>\n<td style=\"width: 118px;text-align: center\">matrix<\/td>\n<td style=\"width: 176px;text-align: center\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24px;text-align: center\">1<\/td>\n<td style=\"width: 52px;text-align: center\">4<\/td>\n<td style=\"width: 118px;text-align: center\">0 \u00a0 5 \u00a0 9 \u00a0 -1<br \/>\n-1 \u00a0 0 \u00a0 2 \u00a0 8<br \/>\n-1 \u00a0 -1 \u00a0 0 \u00a0 7<br \/>\n4 \u00a0 -1 \u00a0-1 \u00a0 0<\/td>\n<td style=\"width: 176px;text-align: center\">16<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24px;text-align: center\">2<\/td>\n<td style=\"width: 52px;text-align: center\">3<\/td>\n<td style=\"width: 118px;text-align: center\">0 \u00a0 -1 \u00a0 2<br \/>\n2 \u00a0 \u00a00 \u00a0-1<br \/>\n4 \u00a0 \u00a01 \u00a0 0<\/td>\n<td style=\"width: 176px;text-align: center\">4<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 24px;text-align: center\">3<\/td>\n<td style=\"width: 52px;text-align: center\">5<\/td>\n<td style=\"width: 118px;text-align: center\">0 \u00a0-1 \u00a0-1 \u00a03 \u00a04<br \/>\n2 \u00a00 \u00a03 \u00a0-1 \u00a04<br \/>\n-1 \u00a04 \u00a00 \u00a0-1 \u00a04<br \/>\n3 \u00a0-1 \u00a02 \u00a00 \u00a01<br \/>\n1 \u00a01 \u00a0-1 \u00a0-1 \u00a00<\/td>\n<td style=\"width: 176px;text-align: center\">8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/www.e-olymp.com\/ru\/submissions\/3397715\">e-olymp<\/a>.<\/p>\n<h3><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/strong><\/h3>\n<pre class=\"lang:java decode:true\">import java.util.*;\r\npublic class Graph {\r\n\r\n    public static void main(String[] args){\r\n        Scanner input =  new Scanner(System.in);\r\n\r\n        int n, max = 0;\r\n        n = input.nextInt();\r\n        int[][] matrix = new int[n][n];\r\n\r\n        for(int i = 0; i &lt; n; i++){\r\n            for(int j = 0; j &lt; n; j++){\r\n                matrix[i][j] = input.nextInt();\r\n            }\r\n        }\r\n\r\n        for(int i = 0; i &lt; n; i++){\r\n            for(int j = 0; j &lt; n; j++){\r\n                for(int k = 0; k &lt; n; k++){\r\n                    if(j != k &amp;&amp; matrix[j][i] != -1 &amp;&amp; matrix[i][k] != -1){\r\n                        if(matrix[j][k] == -1)\r\n                            matrix[j][k] = matrix[j][i] + matrix[i][k];\r\n                        else\r\n                            matrix[j][k] = Math.min(matrix[j][k], matrix[j][i] + matrix[i][k]);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        for(int i = 0; i &lt; n; i++){\r\n            for(int j = 0; j &lt; n; j++){\r\n                if(matrix[i][j] &gt; max) max = matrix[i][j];\r\n            }\r\n        }\r\n\r\n        System.out.println(max);\r\n    }\r\n}\r\n<\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 &#8212; <a href=\"http:\/\/ideone.com\/zpu1MI\">Ideone<\/a>.<\/p>\n<h3><strong>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f<\/strong><\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 <a href=\"https:\/\/neerc.ifmo.ru\/wiki\/index.php?title=%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%A4%D0%BB%D0%BE%D0%B9%D0%B4%D0%B0\">\u0424\u043b\u043e\u0439\u0434\u0430-\u0423\u043e\u0440\u0448\u0435\u043b\u043b\u0430<\/a>, \u0441\u0443\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438\u00a0\u0434\u043b\u0438\u043d \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0438 \u0432\u0435\u0440\u0448\u0438\u043d \u0432\u043e \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u043c \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0435. \u041a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435 \u043f\u043e [latex]i[\/latex], \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u00a0[latex]j[\/latex] \u0438 \u043f\u043e\u00a0[latex]k[\/latex]. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u043c\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0440\u0435\u0431\u0440\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438. \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0424\u043b\u043e\u0439\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 &#8212; \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <span class=\"lang:java decode:true  crayon-inline \">Math.min()<\/span>\u00a0 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u00a0\u0435\u0433\u043e \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0443. \u041f\u043e \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0445 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0445 \u043f\u0443\u0442\u0435\u0439, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445, \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 e-olymp. \u0414\u0430\u043d \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444. \u041d\u0430\u0439\u0442\u0438 \u043f\u0430\u0440\u0443 \u0432\u0435\u0440\u0448\u0438\u043d, \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440 \u0432\u0435\u0440\u0448\u0438\u043d. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0440\u0448\u0438\u043d \u0433\u0440\u0430\u0444\u0430 [latex]n[\/latex] [latex](1 \\leq n \\leq 100)[\/latex]. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 [latex]n[\/latex]\u00a0\u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e [latex]n[\/latex] \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0434\u0430\u044e\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441\u043c\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0430. \u0412 \u043d\u0435\u0439\u00a0-1\u00a0\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=2647\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":93,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[109],"tags":[216,41,278,279,134,192,280],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/2647"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/93"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2647"}],"version-history":[{"count":8,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/2647\/revisions"}],"predecessor-version":[{"id":2656,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/2647\/revisions\/2656"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}