{"id":449,"date":"2020-05-08T16:42:45","date_gmt":"2020-05-08T08:42:45","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=449"},"modified":"2020-05-08T17:53:26","modified_gmt":"2020-05-08T09:53:26","slug":"%e5%ad%98%e5%9b%be","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/05\/08\/%e5%ad%98%e5%9b%be\/","title":{"rendered":"\u5b58\u56fe"},"content":{"rendered":"<p>\u56fe\u7684\u8868\u8fbe\u65b9\u5f0f\u6709\u591a\u79cd<br \/>\n\u8bben\u4e3a\u70b9\u6570\uff0cm\u4e3a\u8fb9\u6570\u3002<\/p>\n<h4>\u90bb\u63a5\u77e9\u9635<\/h4>\n<p>\u7528\u4e8c\u7ef4\u6570\u7ec4\u6765\u5b58\u56fe\uff0c\u5b58\u50a8\u7a7a\u95f4O(<code class=\"katex-inline\">n^2<\/code>)\u3002<br \/>\nG[u][v]\u8868\u793a\u5b58\u5728\u4e00\u6761\u4eceu\u6307\u5411v\u7684\u8fb9\u3002<br \/>\n<img src=\"http:\/\/www.zyhcoding.club:80\/wp-content\/uploads\/2020\/05\/\u90bb\u63a5\u8868\u5b58\u56fe.png\" alt=\"\" \/><\/p>\n<h4>\u90bb\u63a5\u8868<\/h4>\n<p>\u94fe\u5f0f\u5b58\u56fe\u3002<br \/>\n\u94fe\u8868\uff0cvector\u3002\u591a\u7528vector<br \/>\n<img src=\"http:\/\/www.zyhcoding.club:80\/wp-content\/uploads\/2020\/05\/\u90bb\u63a5\u8868\u5b58\u56fe.png\" alt=\"\" \/><\/p>\n<h4>\u8fb9\u96c6\u5b58\u56fe<\/h4>\n<p>\u8fb9\u96c6\u6570\u7ec4\u5b58\u56fe\u3002\u7ed3\u6784\u4f53\u5305\u88c5\u8d77\u70b9\u3001\u7ec8\u70b9\u3001\u6743\u503c\u7b49\u4fe1\u606f\u3002<br \/>\n\u4f46\u7528\u6570\u7ec4\u5b58\u5b8c\u8fd9\u4e9b\u6742\u4e71\u65e0\u7ae0\u7684\u8fb9\u4e4b\u540e\uff0c\u4e00\u822c\u90fd\u4f1a\u5bf9\u5176\u6392\u4e2a\u5e8f\u3002<\/p>\n<h5>\u524d\u5411\u661f<\/h5>\n<p>\u524d\u5411\u661f\u662f\u5728\u8bfb\u5165\u8fb9\u7684\u4fe1\u606f\u540e\uff0c\u5bf9\u8fb9\u96c6\u6570\u7ec4\u4e2d\u7684\u8fb9\u6309\u7167\u8d77\u70b9\u987a\u5e8f\u6392\u5e8f(\u53ef\u7528\u57fa\u6570\u6392\u5e8f\u66f4\u5feb)\u3002<br \/>\n\u8fd9\u6837\u8d77\u70b9\u76f8\u540c\u7684\u8fb9\u5c31\u53ef\u4ee5\u5728\u6570\u7ec4\u8fdb\u884c\u8fde\u7eed\u8bbf\u95ee\u4e86\u3002<br \/>\n<img src=\"http:\/\/www.zyhcoding.club:80\/wp-content\/uploads\/2020\/05\/\u524d\u5411\u661f.png\" alt=\"\" \/><\/p>\n<h5>\u94fe\u5f0f\u524d\u5411\u661f<\/h5>\n<p>\u94fe\u5f0f\u524d\u5411\u661f\u548c\u90bb\u63a5\u8868\u7c7b\u4f3c\uff0c\u53ea\u662f\u7528\u6570\u7ec4\u4ee3\u66ff\u7ed3\u70b9\u4e86\u3002\u6709\u4e24\u4e2a\u6570\u7ec4\u53d8\u91cf: head[], Edge[].<br \/>\nEdge\u662fstruct\u53d8\u91cf<\/p>\n<pre><code class=\"language-c++\">typedef struct edge{\n    int from,to,weight;\n    int next;\n}edge;<\/code><\/pre>\n<p>head[i]\u8868\u793ai\u7ed3\u70b9\u6240\u8fde\u7684\u7b2c\u4e00\u6761\u8fb9\u7684\u4e0b\u6807\uff0c\u7b2c\u4e8c\u6761\u8fb9\u7684\u4e0b\u6807\u662f\u7b2c\u4e00\u6761\u8fb9\u7684next\uff0c\u4f9d\u6b21\u7c7b\u63a8\uff0c\u76f4\u81f3next\u53d6\u503c\u4e3ainf\uff0c\u8868\u793a\u6ca1\u6709\u8fb9\u4e86\u3002<br \/>\n\u6bcf\u6b21\u63d2\u5165\u65b0\u7684\u8fb9\u7684\u65f6\u5019\uff0c\u662f\u63d2\u5728\u8868\u5934\u7684\uff0c\u8fd9\u6837\u80fd\u505a\u5230O(1)\u63d2\u5165\u65b0\u8fb9\u3002<\/p>\n<pre><code class=\"language-c++\">void AddEdge(int from,int to,int weight){\n    tot++;\n    e[tot].from = from;\n    e[tot].to = to;\n    e[tot].weight = weight;\n    e[tot].next = head[from];\n    head[from] = tot;\n}<\/code><\/pre>\n<p>\u94fe\u5f0f\u524d\u5411\u661f\u6548\u679c\u5f88\u597d\uff0c\u7a7a\u95f4\u4e0a\u6ca1\u6709\u6d6a\u8d39\uff0c\u65f6\u95f4\u4e0a\u4e5f\u662f\u6700\u4f18\uff0c\u6bd4vector\u5feb(\u56e0\u4e3avector\u8981push\uff0c\u53ef\u80fd\u4f1a\u6709\u5f88\u5927\u65f6\u95f4\u5f00\u9500)\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56fe\u7684\u8868\u8fbe\u65b9\u5f0f\u6709\u591a\u79cd \u8bben\u4e3a\u70b9\u6570\uff0cm\u4e3a\u8fb9\u6570\u3002 \u90bb\u63a5\u77e9\u9635 \u7528\u4e8c\u7ef4\u6570\u7ec4\u6765\u5b58\u56fe\uff0c\u5b58\u50a8\u7a7a\u95f4O(n^2)\u3002 G[ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/449"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":10,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":463,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/449\/revisions\/463"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}