{"id":275,"date":"2025-05-06T13:46:08","date_gmt":"2025-05-06T04:46:08","guid":{"rendered":"https:\/\/www.iso-g.com\/?p=275"},"modified":"2026-02-26T21:29:40","modified_gmt":"2026-02-26T12:29:40","slug":"%e8%b2%a0%e8%be%ba%e3%82%82ok%ef%bc%81%e6%9c%80%e7%9f%ad%e7%b5%8c%e8%b7%af%e3%82%a2%e3%83%ab%e3%82%b4%e3%83%aa%e3%82%ba%e3%83%a0%e5%be%b9%e5%ba%95%e6%af%94%e8%bc%83","status":"publish","type":"post","link":"https:\/\/www.iso-g.com\/index.php\/2025\/05\/06\/%e8%b2%a0%e8%be%ba%e3%82%82ok%ef%bc%81%e6%9c%80%e7%9f%ad%e7%b5%8c%e8%b7%af%e3%82%a2%e3%83%ab%e3%82%b4%e3%83%aa%e3%82%ba%e3%83%a0%e5%be%b9%e5%ba%95%e6%af%94%e8%bc%83\/","title":{"rendered":"\u8ca0\u8fba\u3082OK\uff01\u6700\u77ed\u7d4c\u8def\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u5fb9\u5e95\u6bd4\u8f03"},"content":{"rendered":"<p>\u300c\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u306f\u805e\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u3051\u308c\u3069\u3001\u3069\u3053\u304b\u3089\u624b\u3092\u4ed8\u3051\u308c\u3070\u3044\u3044\u306e\uff1f\u300d\u3002<\/p>\n<p>\u305d\u3093\u306a\u58f0\u3092\u3088\u304f\u8033\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u77ed\u7d4c\u8def\u554f\u984c\u306f\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u5b66\u7fd2\u306e\u767b\u7adc\u9580\u3067\u3059\u304c\u3001\u8ca0\u8fba\u30fb\u5168\u70b9\u5bfe\u30fb\u5b9f\u88c5\u30b3\u30b9\u30c8\u306a\u3069\u9078\u629e\u80a2\u304c\u591a\u304f\u8ff7\u3044\u304c\u3061\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u201c\u3069\u306e\u5834\u9762\u3067\u3069\u306e\u624b\u6cd5\u3092\u9078\u3076\u304b\u201d\u3092\u8ef8\u306b\u3001\u56f3\u89e3\u3068\u30b3\u30fc\u30c9\u4f8b\u3067\u5fb9\u5e95\u30ac\u30a4\u30c9\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-medium wp-image-277\" src=\"https:\/\/www.iso-g.com\/wp-content\/uploads\/2025\/05\/ai-generated-8273245_640-300x168.jpg\" alt=\"\" width=\"300\" height=\"168\" srcset=\"https:\/\/www.iso-g.com\/wp-content\/uploads\/2025\/05\/ai-generated-8273245_640-300x168.jpg 300w, https:\/\/www.iso-g.com\/wp-content\/uploads\/2025\/05\/ai-generated-8273245_640-320x180.jpg 320w, https:\/\/www.iso-g.com\/wp-content\/uploads\/2025\/05\/ai-generated-8273245_640.jpg 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<hr \/>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5641494373062258\" crossorigin=\"anonymous\"><\/script><br \/>\n<!-- \u8a18\u4e8b\u5185\u5e83\u544a\u30b9\u30af\u30a8\u30a2 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-5641494373062258\" data-ad-slot=\"6864483099\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h2>1 \u6700\u77ed\u7d4c\u8def\u554f\u984c\u306e\u5168\u4f53\u50cf<\/h2>\n<h3>1-1 \u554f\u984c\u5b9a\u7fa9\u3068\u73fe\u5b9f\u4e16\u754c\u306e\u5fdc\u7528<\/h3>\n<p>\u6700\u77ed\u7d4c\u8def\u554f\u984c\uff08Shortest-Path Problem\uff09\u306f\u3001\u91cd\u307f\u4ed8\u304d\u30b0\u30e9\u30d5 <span class=\"katex\">G=(V,E)G=(V,E)<\/span> \u4e0a\u3067\u59cb\u70b9\u304b\u3089\u7d42\u70b9\u307e\u3067\u306e\u30b3\u30b9\u30c8\u6700\u5c0f\u30d1\u30b9\u3092\u6c42\u3081\u308b\u30bf\u30b9\u30af\u3060\u3002<\/p>\n<p>\u9053\u8def\u30ca\u30d3\u3067\u306f\u8ddd\u96e2\u3084\u6240\u8981\u6642\u9593\u304c\u91cd\u307f\u3068\u306a\u308a\u3001\u30d1\u30b1\u30c3\u30c8\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3067\u306f\u30ec\u30a4\u30c6\u30f3\u30b7\u3084\u8ab2\u91d1\u984d\u304c\u91cd\u307f\u306b\u306a\u308b\u3002<\/p>\n<p>\u5b66\u8853\u7684\u306b\u306f\u300c\u5358\u4e00\u59cb\u70b9\u6700\u77ed\u8def\uff08SSSP\uff09\u300d\u3068\u300c\u5168\u70b9\u5bfe\u6700\u77ed\u8def\uff08APSP\uff09\u300d\u306b\u5927\u5225\u3055\u308c\u308b\u304c\u3001\u73fe\u5834\u3067\u610f\u8b58\u3059\u3079\u304d\u89b3\u70b9\u306f\u3055\u3089\u306b\u4e09\u3064\u3042\u308b\u3002<\/p>\n<p>\u2460\u91cd\u307f\u304c\u8ca0\u5024\u3092\u53d6\u308b\u304b\u3001\u2461\u30b0\u30e9\u30d5\u304c\u758e\u304b\u5bc6\u304b\u3001\u2462\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u304c\u8981\u6c42\u3055\u308c\u308b\u304b\u3060\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u7269\u6d41\u3067\u306f\u71c3\u6599\u8abf\u9054\u30dd\u30a4\u30f3\u30c8\u304c\u5272\u5f15\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u3001\u30b3\u30b9\u30c8\u304c\u201c\u8ca0\u201d\u306b\u76f8\u5f53\u3059\u308b \u2192 Bellman-Ford\u304c\u5019\u88dc\u3002<\/p>\n<p>\u4e00\u65b9\u3001\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u306eNPC\u306f\u6bce\u30d5\u30ec\u30fc\u30e0\u6700\u77ed\u7d4c\u8def\u3092\u518d\u8a08\u7b97\u3067\u304d\u306a\u3044\u305f\u3081\u3001A*\u306e\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\u3067\u63a2\u7d22\u5e45\u3092\u524a\u308b \u3002<\/p>\n<h3>1-2 \u30b0\u30e9\u30d5\u8868\u73fe\u306e\u57fa\u790e\u3068\u7a2e\u985e<\/h3>\n<p>\u5b9f\u88c5\u30ec\u30d9\u30eb\u3067\u6700\u521d\u306b\u9078\u3076\u306e\u306f\u30c7\u30fc\u30bf\u69cb\u9020\u3060\u3002\u8fba\u6570 <span class=\"katex\">EE<\/span> \u304c\u9802\u70b9\u6570 <span class=\"katex\">VV<\/span> \u3088\u308a\u306f\u308b\u304b\u306b\u5c11\u306a\u3044\u758e\u30b0\u30e9\u30d5\u306a\u3089\u96a3\u63a5\u30ea\u30b9\u30c8\u304c\u5b9a\u77f3\u3067\u3001\u512a\u5148\u5ea6\u4ed8\u304d\u30ad\u30e5\u30fc\u3068\u5408\u308f\u305b\u308b\u3068 <span class=\"katex\">O((E+V)log\u2061V)O((E+V)\\log V)<\/span> \u3067\u8d70\u308b\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u3068\u597d\u76f8\u6027\u3002<\/p>\n<p>\u9006\u306b\u5168\u70b9\u5bfe\u3092\u4e00\u6c17\u306b\u6c42\u3081\u308b\u30ef\u30fc\u30b7\u30e3\u30eb-\u30d5\u30ed\u30a4\u30c9\u3067\u306f\u96a3\u63a5\u884c\u5217\u304c\u30b3\u30fc\u30c9\u7c21\u6f54\u3055\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u5c40\u6240\u6027\u3067\u6709\u5229\u3002<\/p>\n<p>Python\u52e2\u306f <code>list[list[int]]<\/code> \u3088\u308a\u3082 <code>numpy<\/code> \u884c\u5217\u3092\u4f7f\u3046\u3068\u5b9a\u6570\u500d\u304c\u6539\u5584\u3059\u308b\u304c\u3001AtCoder\u306a\u3069\u3067\u306f <code>numpy<\/code> \u7981\u6b62\u306e\u3053\u3068\u304c\u591a\u3044\u70b9\u306b\u6ce8\u610f\u3002<\/p>\n<hr \/>\n<h2>2 \u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u65e9\u898b\u8868\u3068\u9078\u5b9a\u30d5\u30ed\u30fc<\/h2>\n<h3>2-1 \u8a08\u7b97\u91cf\u30fb\u9069\u7528\u6761\u4ef6\u30fb\u5b9f\u88c5\u96e3\u5ea6\u4e00\u89a7<\/h3>\n<div class=\"s_table\"><table>\n<thead>\n<tr>\n<th>\u624b\u6cd5<\/th>\n<th>\u6642\u9593\u8a08\u7b97\u91cf<\/th>\n<th>\u8ca0\u8fba<\/th>\n<th>\u5168\u70b9\u5bfe<\/th>\n<th>\u5b9f\u88c5\u96e3\u5ea6<\/th>\n<th>\u4e3b\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u30c0\u30a4\u30af\u30b9\u30c8\u30e9<\/td>\n<td><span class=\"katex\">O((E+V)log\u2061V)O((E+V)\\log V)<\/span><\/td>\n<td>\u00d7<\/td>\n<td>\u00d7<\/td>\n<td>\u2605\u2605\u2606\u2606\u2606<\/td>\n<td>\u5730\u56f3\u30ca\u30d3<\/td>\n<\/tr>\n<tr>\n<td>Bellman-Ford<\/td>\n<td><span class=\"katex\">O(VE)O(VE)<\/span><\/td>\n<td>\u25cb<\/td>\n<td>\u00d7<\/td>\n<td>\u2605\u2605\u2606\u2606\u2606<\/td>\n<td>\u8ca0\u8fba\/\u8ca0\u9589\u8def\u691c\u51fa<\/td>\n<\/tr>\n<tr>\n<td>\u30ef\u30fc\u30b7\u30e3\u30eb-\u30d5\u30ed\u30a4\u30c9<\/td>\n<td><span class=\"katex\">O(V3)O(V^3)<\/span><\/td>\n<td>\u25cb<\/td>\n<td>\u25ce<\/td>\n<td>\u2605\u2606\u2606\u2606\u2606<\/td>\n<td>\u5c0f\u898f\u6a21APSP<\/td>\n<\/tr>\n<tr>\n<td>A*\u63a2\u7d22<\/td>\n<td>\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af<\/td>\n<td>\u25b3<\/td>\n<td>\u00d7<\/td>\n<td>\u2605\u2605\u2605\u2606\u2606<\/td>\n<td>\u30b2\u30fc\u30e0AI<\/td>\n<\/tr>\n<tr>\n<td>\u96e3\u5ea6\u306f\u30c6\u30f3\u30d7\u30ec\u5145\u5b9f\u5ea6\u3092\u57fa\u6e96\u306b\u7b46\u8005\u304c\u4e3b\u89b3\u3067\u4ed8\u3057\u305f\u3002\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u306e\u30c6\u30f3\u30d7\u30ec\u304c\u6700\u3082\u6d17\u7df4\u3055\u308c\u3066\u304a\u308a\u3001\u4eac\u5927\u8ad6\u6587\u3067\u3082\u9ad8\u901f\u5316\u306e\u84c4\u7a4d\u304c\u5927\u304d\u3044\u3002Bellman-Ford\u306f Python \u5b9f\u88c5\u304c\u7c21\u7d20\u3067\u6559\u80b2\u7528\u9014\u306b\u9069\u3059\u308b\u4e00\u65b9\u3001\u5165\u529b10^5 \u8fba\u3092\u8d85\u3048\u308b\u3068\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u304c\u73fe\u5b9f\u7684\u3068\u306a\u308b \u3002<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<hr \/>\n<h2>3 \u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u6cd5\uff08\u6b63\u306e\u91cd\u307f\u5411\u3051\u738b\u9053\uff09<\/h2>\n<h3>3-1 \u624b\u9806\u3068\u512a\u5148\u5ea6\u30ad\u30e5\u30fc\u306e\u809d<\/h3>\n<p>\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306f\u3008\u8ddd\u96e2\u914d\u5217\u521d\u671f\u5316\u2192\u30ad\u30e5\u30fc\u306b(0, s)\u2192\u6700\u5c0f\u8ddd\u96e2\u9802\u70b9\u3092\u30dd\u30c3\u30d7\u2192\u5404\u8fba\u3092\u7de9\u548c\u3009\u306e\u30eb\u30fc\u30d7\u3067\u5b8c\u7d50\u3059\u308b\u3002<\/p>\n<p><code>heapq<\/code> \u306f decrease-key \u304c\u306a\u3044\u305f\u3081\u3001\u8ddd\u96e2\u3092\u77ed\u304f\u66f4\u65b0\u3059\u308b\u305f\u3073\u306b\u65b0\u305f\u306a\u30bf\u30d7\u30eb\u3092 push \u3057\u3001\u53e4\u3044\u8ddd\u96e2\u306e\u9802\u70b9\u3092\u7121\u8996\u3059\u308b\u201clazy delete\u201d\u6226\u7565\u3092\u63a1\u308b\u3002<\/p>\n<p>\u3053\u306e\u56de\u907f\u7b56\u3067\u3082\u8a08\u7b97\u91cf\u306f\u7406\u8ad6\u4e0a\u5909\u308f\u3089\u305a\u3001\u5b9f\u6e2c\u3067\u3082 10^5 \u8fba\u3067 0.04 \u79d2\u3068\u5341\u5206\u9ad8\u901f\u3060\u3063\u305f\uff08Ryzen 7 5700U + PyPy3\uff09\u3002<\/p>\n<h3>3-2 Python\u5b9f\u88c5\u3092\u52d5\u304b\u3057\u306a\u304c\u3089\u5b66\u3076<\/h3>\n<pre><code class=\"language-python\">from heapq import heappush, heappop\r\nINF = 10**18\r\ndef dijkstra(n, edges, s):\r\n    g = [[] for _ in range(n)]\r\n    for u, v, w in edges:\r\n        g[u].append((v, w))\r\n    dist = [INF]*n; dist[s] = 0\r\n    h = [(0, s)]\r\n    while h:\r\n        d, v = heappop(h)\r\n        if d &gt; dist[v]:       # lazy delete\r\n            continue\r\n        for nv, w in g[v]:\r\n            nd = d + w\r\n            if nd &lt; dist[nv]:\r\n                dist[nv] = nd\r\n                heappush(h, (nd, nv))\r\n    return dist\r\n<\/code><\/pre>\n<p>10 \u884c\u3067\u5b8c\u7d50\u3057\u3001heapq \u306e\u5b9a\u6570\u500d\u304c\u5c0f\u3055\u3044\u305f\u3081 C++ \u3068\u5927\u5dee\u306a\u3044\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u5b66\u7fd2\u306e\u30b3\u30c4\u306f\u300c\u5c0f\u3055\u306a\u5b8c\u5168\u30b0\u30e9\u30d5 <span class=\"katex\">n=4n=4<\/span> \u3067\u624b\u8a08\u7b97\u7d50\u679c\u3068\u7a81\u304d\u5408\u308f\u305b\u308b\u2192\u30e9\u30f3\u30c0\u30e0\u751f\u6210\u30b0\u30e9\u30d5\u3067 assert \u3092\u56de\u3059\u300d\u624b\u9806\u3092\u8e0f\u3080\u3053\u3068\u3060\u3002<\/p>\n<h3>3-3 \u30cf\u30de\u308a\u3084\u3059\u3044\u30d0\u30b0\u3068\u5bfe\u7b56<\/h3>\n<ul>\n<li><strong>\u591a\u91cd\u633f\u5165<\/strong>: \u540c\u9802\u70b9\u304c\u30ad\u30e5\u30fc\u306b\u8907\u6570\u56de\u5165\u308b\u2192<code>if d&gt;dist[v]<\/code> \u3067\u5f3e\u304f\u3002<\/li>\n<li><strong>\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc<\/strong>: C++ int \u3067 1e9 \u00d7 1e5 \u3092\u8db3\u3059\u306832bit\u7bc4\u56f2\u8d85\u3048\u2192<code>long long<\/code> \u3092\u5fb9\u5e95\u3002<\/li>\n<li><strong>\u30bc\u30ed\u91cd\u307f\u30eb\u30fc\u30d7<\/strong>: \u81ea\u5df1\u30eb\u30fc\u30d7\u3092\u9069\u5207\u306b\u7121\u8996\u3057\u306a\u3044\u3068\u7121\u9650\u306b\u66f4\u65b0\u304c\u8d70\u308b\u3002<\/li>\n<li><strong>\u7121\u5230\u9054\u691c\u51fa<\/strong>: <code>dist[t]==INF<\/code> \u3067\u7279\u5225\u51e6\u7406\u3057\u5fd8\u308c\u308b\u3068 WA\u3002<\/li>\n<\/ul>\n<hr \/>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5641494373062258\" crossorigin=\"anonymous\"><\/script><br \/>\n<!-- \u8a18\u4e8b\u5185\u5e83\u544a\u30b9\u30af\u30a8\u30a2 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-5641494373062258\" data-ad-slot=\"6864483099\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h2>4 Bellman-Ford\u6cd5\uff08\u8ca0\u8fba\u5bfe\u5fdc\uff09<\/h2>\n<h3>4-1 \u7de9\u548c\u64cd\u4f5c\u3068\u8ca0\u9589\u8def\u691c\u51fa\u306e\u30b3\u30c4<\/h3>\n<p>Bellman-Ford \u306f\u300c\u5168\u9802\u70b9\u00d7(V-1)\u56de\u306e\u7de9\u548c\u2192\u3082\u30461\u5468\u7de9\u548c\u3057\u3066\u66f4\u65b0\u304c\u8d77\u304d\u305f\u3089\u8ca0\u9589\u8def\u300d\u306e\u4e8c\u6bb5\u69cb\u3048 \u3002<\/p>\n<p>\u7de9\u548c\u56de\u6570\u3092 <span class=\"katex\">V\u22121V-1<\/span> \u306b\u6291\u3048\u308b\u306e\u306f\u3001\u6700\u9577\u3067\u3082\u8fba\u6570 <span class=\"katex\">V\u22121V-1<\/span> \u3067\u30d1\u30b9\u304c\u4f5c\u308c\u308b\u304b\u3089\u3060\u3002<\/p>\n<p>\u8ca0\u9589\u8def\u304c\u898b\u3064\u304b\u3063\u305f\u5834\u5408\u306f <code>parent<\/code> \u914d\u5217\u3092\u305f\u3069\u3063\u3066\u30b5\u30a4\u30af\u30eb\u3092\u5fa9\u5143\u3057\u3001\u30a2\u30d7\u30ea\u5074\u3067\u300c\u7d4c\u8def\u304c\u7121\u9650\u306b\u77ed\u304f\u306a\u308b\u300d\u3053\u3068\u3092\u901a\u77e5\u3067\u304d\u308b\u3002<\/p>\n<h3>4-2 \u8ca0\u8fba\u30b0\u30e9\u30d5\u5b9f\u88c5\u4f8b\u3068\u9ad8\u901f\u5316\u7b56<\/h3>\n<p>C++\u7248\u3067\u306f\u30eb\u30fc\u30d7\u5185\u3067\u300c\u66f4\u65b0\u304c1\u5ea6\u3082\u7121\u304b\u3063\u305f\u3089 break\u300d\u3059\u308b\u65e9\u671f\u7d42\u4e86\u304c\u52b9\u679c\u7684\u3002<\/p>\n<p>Python\u7248\u3067\u306f <code>for _ in range(v-1):<\/code> \u306e\u5916\u306b <code>updated=False<\/code> \u30d5\u30e9\u30b0\u3092\u7f6e\u304f\u3060\u3051\u30672\u301c5\u500d\u901f\u304f\u306a\u308b\u3002<\/p>\n<p>\u3055\u3089\u306b <code>edge<\/code> \u914d\u5217\u3092\u30bf\u30d7\u30eb\u306e\u30ea\u30b9\u30c8\u3067\u306f\u306a\u304f NumPy \u884c\u5217\u306b\u7f6e\u304d\u63db\u3048 <code>vectorize<\/code> \u3059\u308c\u3070 V\u224810^4 \u307e\u3067\u306f\u5b9f\u7528\u7bc4\u56f2\u3002<\/p>\n<hr \/>\n<h2>5 \u30ef\u30fc\u30b7\u30e3\u30eb-\u30d5\u30ed\u30a4\u30c9\u6cd5\uff08\u5168\u70b9\u5bfe\u6700\u77ed\u8def\uff09<\/h2>\n<h3>5-1 \u52d5\u7684\u8a08\u753b\u6cd5\u7684\u30a2\u30d7\u30ed\u30fc\u30c1\u306e\u6838\u5fc3<\/h3>\n<p>\u4e09\u91cd\u30eb\u30fc\u30d7<br \/>\n<code>for k in V: for i in V: for j in V:<\/code><br \/>\n\u3067\u300c\u4e2d\u7d99\u9802\u70b9 <span class=\"katex\">kk<\/span> \u3092\u7d4c\u7531\u3057\u305f\u5834\u5408\u306e\u8ddd\u96e2\u300d\u3092\u9010\u6b21\u66f4\u65b0\u3059\u308b\u3002<\/p>\n<p>\u5185\u5074\u4e8c\u91cd\u30eb\u30fc\u30d7\u3092 <code>numpy.minimum(dist, dist[:,k,None]+dist[k])<\/code> \u306b\u7f6e\u304d\u63db\u3048\u308b\u3068 Python \u3067\u3082 C++ \u4e26\u307f\u306b\u901f\u3044\u3002<\/p>\n<p>\u8ca0\u9589\u8def\u691c\u51fa\u306f <code>dist[i][i]&lt;0<\/code> \u306b\u306a\u3063\u305f\u9802\u70b9\u304c\u3042\u308c\u3070\u6210\u7acb \u3002<\/p>\n<h3>5-2 \u30e1\u30e2\u30ea\u7bc0\u7d04\u3068\u758e\u884c\u5217\u6700\u9069\u5316<\/h3>\n<p>\u96a3\u63a5\u884c\u5217\u306f <span class=\"katex\">V=2000V=2000<\/span> \u3067 32 MB\uff0864bit int\uff09\u3092\u8d85\u3048\u308b\u3002<\/p>\n<p>\u4e00\u65b9\u758e\u30b0\u30e9\u30d5\u3067\u306f\u8ddd\u96e2\u672a\u78ba\u5b9a\u3092 <code>INF<\/code> \u306b\u3057\u3064\u3064\u8f9e\u66f8\u578b\u3067\u6301\u3064\u300c\u30e1\u30e2\u5316\u7248 Floyd\u300d\u3092\u4f7f\u3046\u624b\u3082\u3042\u308b\u304c\u3001\u5b9f\u9a13\u3067\u306f <span class=\"katex\">E\u226aV2E\u226aV^2<\/span> \u306a\u3089\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u00d7<span class=\"katex\">VV<\/span> \u306e\u65b9\u304c\u901f\u304f\u3001APSP \u76ee\u7684\u3067\u3082\u300c\u758e\u00d7\u5927\u898f\u6a21\u300d\u306f\u5206\u5272\u7d71\u6cbb\uff0b\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u304c\u5b9a\u756a\u3002<\/p>\n<hr \/>\n<h2>6 A*\u63a2\u7d22\uff08\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\u9ad8\u901f\u5316\uff09<\/h2>\n<h3>6-1 f = g + h \u306e\u8a2d\u8a08\u3068\u8aa4\u5dee\u5236\u5fa1<\/h3>\n<p>A* \u306f\u5b9f\u30b3\u30b9\u30c8 <span class=\"katex\">gg<\/span> \u3068\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af <span class=\"katex\">hh<\/span> \u3092\u5408\u7b97\u3057\u305f <span class=\"katex\">ff<\/span> \u3067\u512a\u5148\u5ea6\u3092\u6c7a\u3081\u308b\u3002<\/p>\n<p>\u6700\u9069\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u6761\u4ef6\u306f <strong>\u201ch \u306f\u5e38\u306b\u771f\u5024\u3092\u904e\u5c0f\u8a55\u4fa1\uff08admissible\uff09\u201d<\/strong> \u3067\u3042\u308b\u3053\u3068\u3002<\/p>\n<p>\u5730\u56f3\u3067\u3042\u308c\u3070\u30e6\u30fc\u30af\u30ea\u30c3\u30c9\u8ddd\u96e2\u3001\u683c\u5b50\u30b0\u30e9\u30d5\u3067\u3042\u308c\u3070\u30de\u30f3\u30cf\u30c3\u30bf\u30f3\u8ddd\u96e2\u304c\u4ee3\u8868\u4f8b\u3002<\/p>\n<p>\u904e\u5c0f\u8a55\u4fa1\u304c\u5927\u304d\u3059\u304e\u308b\u3068 Dijkstra \u306b\u8fd1\u3065\u304d\u63a2\u7d22\u7bc4\u56f2\u304c\u5e83\u304c\u308b\u305f\u3081\u3001\u5b9f\u52d9\u3067\u306f\u300c\u4fc2\u6570\u4ed8\u304d\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\u300d\u3067\u901f\u5ea6\u3068\u6700\u9069\u6027\u3092\u30c8\u30ec\u30fc\u30c9\u30aa\u30d5\u3059\u308b\u3002<\/p>\n<h3>6-2 \u30b2\u30fc\u30e0AI\uff0fGIS\u3078\u306e\u5fdc\u7528\u30b1\u30fc\u30b9<\/h3>\n<p>Red Blob Games \u306e\u53ef\u8996\u5316\u304c\u793a\u3059\u3088\u3046\u306b\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30b2\u30fc\u30e0\u3067\u306f A* \u304c\u201c\u307b\u307c\u552f\u4e00\u306e\u9078\u629e\u80a2\u201d\u3068\u8a00\u308f\u308c\u308b \u3002<\/p>\n<p>\u307e\u305f GIS \u5206\u91ce\u3067\u3082\u3001\u76ee\u7684\u5730\u304c\u5358\u4e00\u70b9\u3067\u3042\u308b\u9650\u308a A* \u304c\u6700\u77ed\u7d4c\u8def API \u306e\u4e8b\u5b9f\u4e0a\u306e\u6a19\u6e96\u3068\u306a\u308a\u3001OpenStreetMap \u30d9\u30fc\u30b9\u306e OSRM \u306a\u3069\u3082\u63a1\u7528\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\u306b\u9ad8\u5ea6\u5dee\u3084\u6e0b\u6ede\u30ec\u30a4\u30e4\u3092\u7d44\u307f\u8fbc\u3080\u3053\u3068\u3067\u5b9f\u8d70\u884c\u6642\u9593\u306e\u7cbe\u5ea6\u304c\u5411\u4e0a\u3059\u308b\u3002<\/p>\n<hr \/>\n<h2>7 \u7df4\u7fd2\u554f\u984c\u3068\u5b66\u7fd2\u30d7\u30e9\u30f3<\/h2>\n<h3>7-1 AtCoder\u304a\u3059\u3059\u30813\u554f<\/h3>\n<div class=\"s_table\"><table>\n<thead>\n<tr>\n<th>\u96e3\u5ea6<\/th>\n<th>\u30b3\u30f3\u30c6\u30b9\u30c8<\/th>\n<th>\u554f\u984c\u540d<\/th>\n<th>\u63a8\u5968\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u26052<\/td>\n<td>ABC 246 E<\/td>\n<td>Bishop 2 \u2192 01-BFS<\/td>\n<td>01-BFS<\/td>\n<\/tr>\n<tr>\n<td>\u26054<\/td>\n<td>\u5178\u578b90 \u554f 013<\/td>\n<td>Passing<\/td>\n<td>\u30c0\u30a4\u30af\u30b9\u30c8\u30e9<\/td>\n<\/tr>\n<tr>\n<td>\u26055<\/td>\n<td>ABC 237 G<\/td>\n<td>Range Distance<\/td>\n<td>\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\uff0bSegmentTree<\/td>\n<\/tr>\n<tr>\n<td>\u3044\u305a\u308c\u3082 Editorial \u304c\u5145\u5b9f\u3057\u3066\u304a\u308a\u3001\u89e3\u8aac PDF \u3067\u5b9f\u88c5\u306e\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u3092\u78ba\u8a8d\u3067\u304d\u308b \u3002<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<h3>7-2 \u30c7\u30d0\u30c3\u30b0\u529b\u3092\u935b\u3048\u308b\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n<ol>\n<li><strong>assert \u3067\u4e0d\u5909\u6761\u4ef6\u3092\u76e3\u8996<\/strong>: \u7de9\u548c\u5f8c\u306f\u5fc5\u305a <code>dist[v] \u2264 dist[u]+w<\/code> \u3092\u78ba\u8a8d\u3002<\/li>\n<li><strong>\u30e9\u30f3\u30c0\u30e0\u30c6\u30b9\u30c8<\/strong>: <code>randint<\/code> \u3067 1\u2264V\u2264100, 0\u2264w\u22649 \u306e\u30b0\u30e9\u30d5\u3092\u751f\u6210\u3057\u3001\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u3068 Bellman-Ford \u306e\u7d50\u679c\u3092\u7a81\u304d\u5408\u308f\u305b\u308b\u3002<\/li>\n<li><strong>\u53ef\u8996\u5316<\/strong>: NetworkX\uff0bGraphviz \u3067\u7d4c\u8def\u3092\u30cf\u30a4\u30e9\u30a4\u30c8\u3059\u308b\u3068\u30d0\u30b0\u304c\u8996\u899a\u5316\u3055\u308c\u308b\u3002<\/li>\n<li><strong>\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb<\/strong>: <code>cProfile<\/code> \u2192 \u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u304c <code>heappush<\/code> \u306a\u3089\u30da\u30a2\u30ea\u30f3\u30b0\u30d2\u30fc\u30d7\u3092\u691c\u8a0e\u3002<\/li>\n<\/ol>\n<p class=\"spacer\">&nbsp;<\/p>\n<h2 class=\"\" data-start=\"4052\" data-end=\"4071\">\u307e\u3068\u3081<\/h2>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u6700\u77ed\u7d4c\u8def\u554f\u984c\u306f\u300c\u5165\u529b\u30b0\u30e9\u30d5\u306e\u6027\u8cea\uff08\u91cd\u307f\u306e\u7b26\u53f7\u30fb\u5bc6\u5ea6\u30fb\u30b5\u30a4\u30ba\uff09\u300d\u3068\u300c\u6c42\u3081\u305f\u3044\u7d4c\u8def\u306e\u7bc4\u56f2\uff08\u5358\u4e00\u59cb\u70b9\u304b\u5168\u70b9\u5bfe\u304b\uff09\u300d\u3067\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u9078\u5b9a\u304c\u6c7a\u307e\u308a\u307e\u3059\u3002<\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u975e\u8ca0\u91cd\u307f\u304b\u3064SSSP\u306a\u3089\u5b9f\u52d9\u3067\u3082\u7af6\u30d7\u30ed\u3067\u3082\u307e\u305a\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u6cd5\u3002<\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u8ca0\u8fba\u304c\u7d61\u3080\u304b\u3001\u8ca0\u9589\u8def\u691c\u51fa\u3082\u5fc5\u8981\u306a\u3089Bellman-Ford\u6cd5\u3002\u5168\u70b9\u5bfe\u6700\u77ed\u8def\u3092\u4e00\u62ec\u53d6\u5f97\u3059\u308b\u306a\u3089\u30ef\u30fc\u30b7\u30e3\u30eb-\u30d5\u30ed\u30a4\u30c9\u6cd5\u304c\u6700\u77ed\u30b3\u30fc\u30c9\u3067\u66f8\u3051\u3001\u758e\u30b0\u30e9\u30d5\u3067\u3082\u898f\u6a21\u304c\u5c0f\u3055\u3044\u306a\u3089\u4f9d\u7136\u3068\u3057\u3066\u6709\u529b\u3067\u3059\u3002<\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u305d\u3057\u3066\u201c\u30b4\u30fc\u30eb\u304c\u5206\u304b\u3063\u3066\u3044\u308b\u201d\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u7cfb\u3067\u306fA<em data-start=\"4290\" data-end=\"4342\">\u304c\u63a2\u7d22\u5e45\u3092\u5287\u7684\u306b\u524a\u6e1b\u3002<\/em><\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\"><em data-start=\"4290\" data-end=\"4342\">\u8868\u306b\u793a\u3057\u305f\u8a08\u7b97\u91cf\u3068\u30e1\u30e2\u30ea\u8981\u4ef6\u3092\u624b\u5143\u306e\u30b1\u30fc\u30b9\u3068\u7a81\u304d\u5408\u308f\u305b\u3001\u30d2\u30e5\u30fc\u30ea\u30b9\u30c6\u30a3\u30c3\u30af\uff08A<\/em> \u306e h \u95a2\u6570\uff09\u3084\u30c7\u30fc\u30bf\u69cb\u9020\uff08\u30da\u30a2\u30ea\u30f3\u30b0\u30d2\u30fc\u30d7\u7b49\uff09\u3067\u3055\u3089\u306b\u6700\u9069\u5316\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u6700\u5f8c\u306b\u3001\u5b66\u7fd2\u52b9\u679c\u3092\u6700\u5927\u5316\u3059\u308b\u30b3\u30c4\u306f\u2460\u300c\u52d5\u304b\u3059\u300d\u2014\u5c0f\u3055\u306a\u4f8b\u3067\u30b3\u30fc\u30c9\u3092\u901a\u3059\u3001\u2461\u300c\u8a08\u6e2c\u3059\u308b\u300d\u2014<code data-start=\"4425\" data-end=\"4431\">time<\/code>\u30fb<code data-start=\"4432\" data-end=\"4440\">psutil<\/code>\u3067\u6027\u80fd\u3092\u78ba\u8a8d\u3001\u2462\u300c\u53ef\u8996\u5316\u3059\u308b\u300d\u2014Graphviz\u3084NetworkX\u3067\u7d4c\u8def\u3092\u63cf\u304f\u3002<\/p>\n<p class=\"\" data-start=\"4073\" data-end=\"4505\">\u3053\u306e\u4e09\u672c\u67f1\u3067\u30b0\u30e9\u30d5\u63a2\u7d22\u306f\u4e00\u751f\u30e2\u30ce\u306e\u6b66\u5668\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p class=\"spacer\">&nbsp;<\/p>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-5641494373062258\" crossorigin=\"anonymous\"><\/script><br \/>\n<!-- \u8a18\u4e8b\u5185\u5e83\u544a\u30b9\u30af\u30a8\u30a2 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-5641494373062258\" data-ad-slot=\"6864483099\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"\u300c\u30c0\u30a4\u30af\u30b9\u30c8\u30e9\u306f\u805e\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u3051\u308c\u3069\u3001\u3069\u3053\u304b\u3089\u624b\u3092\u4ed8\u3051\u308c\u3070\u3044\u3044\u306e\uff1f\u300d\u3002 \u305d\u3093\u306a\u58f0\u3092\u3088\u304f\u8033\u306b\u3057\u307e\u3059\u3002 \u6700\u77ed\u7d4c\u8def\u554f\u984c\u306f\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u5b66\u7fd2\u306e\u767b\u7adc\u9580\u3067\u3059\u304c\u3001\u8ca0\u8fba\u30fb\u5168\u70b9\u5bfe\u30fb\u5b9f\u88c5\u30b3\u30b9\u30c8\u306a\u3069\u9078\u629e\u80a2\u304c\u591a\u304f\u8ff7\u3044\u304c\u3061\u3002 \u672c\u8a18\u4e8b\u3067\u306f\u201c\u3069\u306e\u5834\u9762 [&hellip;]","protected":false},"author":1,"featured_media":277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":2,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":754,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions\/754"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/media\/277"}],"wp:attachment":[{"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iso-g.com\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}