{"id":33884,"date":"2024-11-01T09:21:39","date_gmt":"2024-11-01T09:21:39","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33884"},"modified":"2024-11-01T10:55:26","modified_gmt":"2024-11-01T10:55:26","slug":"c-coding-test-course-floyd-warshall","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33884\/","title":{"rendered":"C# Coding Test Course, Floyd-Warshall"},"content":{"rendered":"<article>\n<header>\n<p>Date: October 1, 2023<\/p>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>\n            Algorithm problems are one of the important elements in coding tests, especially graph algorithms are used effectively in many situations.<br \/>\n            In this article, we will solve a problem using the Floyd-Warshall algorithm.<br \/>\n            The Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices and mainly uses dynamic programming techniques.\n        <\/p>\n<\/section>\n<section>\n<h2>Problem Description<\/h2>\n<h3>Problem: Finding the Shortest Path<\/h3>\n<p>\n            All campuses of your university are represented as vertices, and the roads connecting the campuses are represented as edges.<br \/>\n            Calculate the distance of the shortest path from campus A to campus B. Follow the input format below.\n        <\/p>\n<pre>\n            Input:\n            - First line: Total number of campuses N (1 \u2264 N \u2264 100)\n            - Second line: Number of roads M (1 \u2264 M \u2264 10000)\n            - The next M lines: Information about each road in the form (A, B, C), meaning the length of the road from A to B is C.\n            \n            Output:\n            - Print the distance matrix of the shortest paths between campuses.\n        <\/pre>\n<\/section>\n<section>\n<h2>Algorithm Overview<\/h2>\n<p>\n            The Floyd-Warshall algorithm is based on the following fundamental principle.<br \/>\n            For every pair of vertices (i, j), it compares the distance from i to j through k with the direct path distance and updates the shortest path.\n        <\/p>\n<pre>\n            D[i][j] = min(D[i][j], D[i][k] + D[k][j])\n        <\/pre>\n<p>\n            This algorithm has a time complexity of O(N^3) and can efficiently compute the shortest paths between all pairs of vertices.\n        <\/p>\n<\/section>\n<section>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Input Handling<\/h3>\n<p>\n            To handle input, initialize the array and receive road information.<br \/>\n            After initializing the distances to infinity, set the distances between directly connected campuses.<br \/>\n            This creates the initial distance matrix D.\n        <\/p>\n<h3>Step 2: Implementing the Floyd-Warshall Algorithm<\/h3>\n<p>\n            Update the minimum distances between each pair of campuses through three nested loops.<br \/>\n            In each iteration, check if there is a shorter path via k, and if so, update the distance matrix.\n        <\/p>\n<h3>Step 3: Output the Result<\/h3>\n<p>\n            Print the updated distance matrix. Remaining infinite distances indicate unreachable campuses.\n        <\/p>\n<\/section>\n<section>\n<h2>C# Code Implementation<\/h2>\n<pre>\n            <code>\n            using System;\n            using System.Linq;\n\n            class Program\n            {\n                const int INF = 987654321; \/\/ Define infinity value\n\n                static void Main(string[] args)\n                {\n                    \/\/ Input handling\n                    int N = int.Parse(Console.ReadLine());\n                    int M = int.Parse(Console.ReadLine());\n\n                    int[,] D = new int[N + 1, N + 1];\n\n                    \/\/ Initialize distance array\n                    for (int i = 1; i &lt;= N; i++)\n                    {\n                        for (int j = 1; j &lt;= N; j++)\n                        {\n                            if (i == j) D[i, j] = 0;\n                            else D[i, j] = INF; \/\/ Initialize to infinity\n                        }\n                    }\n\n                    \/\/ Input road information into distance array\n                    for (int i = 0; i &lt; M; i++)\n                    {\n                        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n                        int A = input[0], B = input[1], C = input[2];\n                        D[A, B] = Math.Min(D[A, B], C); \/\/ Set to minimum value as there could be multiple roads\n                    }\n\n                    \/\/ Floyd-Warshall algorithm\n                    for (int k = 1; k &lt;= N; k++)\n                    {\n                        for (int i = 1; i &lt;= N; i++)\n                        {\n                            for (int j = 1; j &lt;= N; j++)\n                            {\n                                D[i, j] = Math.Min(D[i, j], D[i, k] + D[k, j]);\n                            }\n                        }\n                    }\n\n                    \/\/ Output results\n                    for (int i = 1; i &lt;= N; i++)\n                    {\n                        for (int j = 1; j &lt;= N; j++)\n                        {\n                            if (D[i, j] == INF) Console.Write(\"INF \");\n                            else Console.Write(D[i, j] + \" \");\n                        }\n                        Console.WriteLine();\n                    }\n                }\n            }\n            <\/code>\n        <\/pre>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>\n            In this article, we discussed the shortest path problem using the Floyd-Warshall algorithm.<br \/>\n            This algorithm is effective in finding the shortest paths between all pairs of vertices and is widely used in real situations.<br \/>\n            It is important to understand and apply the Floyd-Warshall algorithm to solve various graph problems.\n        <\/p>\n<\/section>\n<footer>\n<p>Author: Algorithm Blogger<\/p>\n<\/footer>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>Date: October 1, 2023 Introduction Algorithm problems are one of the important elements in coding tests, especially graph algorithms are used effectively in many situations. In this article, we will solve a problem using the Floyd-Warshall algorithm. The Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices and mainly uses &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33884\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C# Coding Test Course, Floyd-Warshall&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[90],"tags":[],"class_list":["post-33884","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/33884\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Date: October 1, 2023 Introduction Algorithm problems are one of the important elements in coding tests, especially graph algorithms are used effectively in many situations. In this article, we will solve a problem using the Floyd-Warshall algorithm. The Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices and mainly uses &hellip; \ub354 \ubcf4\uae30 &quot;C# Coding Test Course, Floyd-Warshall&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33884\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:21:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:55:26+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C# Coding Test Course, Floyd-Warshall\",\"datePublished\":\"2024-11-01T09:21:39+00:00\",\"dateModified\":\"2024-11-01T10:55:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/\"},\"wordCount\":309,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C# Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33884\/\",\"name\":\"C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:21:39+00:00\",\"dateModified\":\"2024-11-01T10:55:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33884\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33884\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Coding Test Course, Floyd-Warshall\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/33884\/","og_locale":"ko_KR","og_type":"article","og_title":"C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Date: October 1, 2023 Introduction Algorithm problems are one of the important elements in coding tests, especially graph algorithms are used effectively in many situations. In this article, we will solve a problem using the Floyd-Warshall algorithm. The Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices and mainly uses &hellip; \ub354 \ubcf4\uae30 \"C# Coding Test Course, Floyd-Warshall\"","og_url":"https:\/\/atmokpo.com\/w\/33884\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:21:39+00:00","article_modified_time":"2024-11-01T10:55:26+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33884\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33884\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C# Coding Test Course, Floyd-Warshall","datePublished":"2024-11-01T09:21:39+00:00","dateModified":"2024-11-01T10:55:26+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33884\/"},"wordCount":309,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C# Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33884\/","url":"https:\/\/atmokpo.com\/w\/33884\/","name":"C# Coding Test Course, Floyd-Warshall - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:21:39+00:00","dateModified":"2024-11-01T10:55:26+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33884\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33884\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33884\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C# Coding Test Course, Floyd-Warshall"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33884"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33884\/revisions"}],"predecessor-version":[{"id":33885,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33884\/revisions\/33885"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}