{"id":351856,"date":"2021-02-05T07:18:54","date_gmt":"2021-02-04T23:18:54","guid":{"rendered":"http:\/\/4563.org\/?p=351856"},"modified":"2021-02-05T07:18:54","modified_gmt":"2021-02-04T23:18:54","slug":"%e4%ba%9a%e9%a9%ac%e9%80%8a%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e5%b0%bd%e9%87%8f%e5%87%8f%e5%b0%91%e6%81%b6%e6%84%8f%e8%bd%af%e4%bb%b6%e7%9a%84%e4%bc%a0%e6%92%ad-ii","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=351856","title":{"rendered":"\u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h3>\u63cf\u8ff0<\/h3>\n<p>\u5728\u8282\u70b9\u7f51\u7edc\u4e2d\uff0c\u53ea\u6709\u5f53 graph[i][j] = 1 \u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9 i \u80fd\u591f\u76f4\u63a5\u8fde\u63a5\u5230\u53e6\u4e00\u4e2a\u8282\u70b9 j \u3002<\/p>\n<p>\u4e00\u4e9b\u8282\u70b9 initial \u6700\u521d\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u53ea\u8981\u4e24\u4e2a\u8282\u70b9\u76f4\u63a5\u8fde\u63a5\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u53d7\u5230\u6076\u610f\u8f6f\u4ef6\u7684\u611f\u67d3\uff0c\u90a3\u4e48\u4e24\u4e2a\u8282\u70b9\u90fd\u5c06\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u8fd9\u79cd\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad\u5c06\u7ee7\u7eed\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8282\u70b9\u53ef\u4ee5\u88ab\u8fd9\u79cd\u65b9\u5f0f\u611f\u67d3\u3002<\/p>\n<p>\u5047\u8bbe M(initial) \u662f\u5728\u6076\u610f\u8f6f\u4ef6\u505c\u6b62\u4f20\u64ad\u4e4b\u540e\uff0c\u6574\u4e2a\u7f51\u7edc\u4e2d\u611f\u67d3\u6076\u610f\u8f6f\u4ef6\u7684\u6700\u7ec8\u8282\u70b9\u6570\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4ece\u521d\u59cb\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u5b8c\u5168\u79fb\u9664\u8be5\u8282\u70b9\u4ee5\u53ca\u4ece\u8be5\u8282\u70b9\u5230\u4efb\u4f55\u5176\u4ed6\u8282\u70b9\u7684\u4efb\u4f55\u8fde\u63a5\u3002\u5982\u679c\u79fb\u9664\u8fd9\u4e00\u8282\u70b9\u5c06\u6700\u5c0f\u5316 M(initial)\uff0c \u5219\u8fd4\u56de\u8be5\u8282\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6\uff0c\u5c31\u8fd4\u56de\u7d22\u5f15\u6700\u5c0f\u7684\u8282\u70b9\u3002<\/p>\n<ol>\n<li>1 &lt; graph.length = graph[0].length &lt;= 300<\/li>\n<li>0 &lt;= graph[i][j] == graph[j][i] &lt;= 1<\/li>\n<li>graph[i][i] = 1<\/li>\n<li>1 &lt;= initial.length &lt; graph.length<\/li>\n<li>0 &lt;= initial[i] &lt; graph.length<\/li>\n<\/ol>\n<p>\u5728\u7ebf\u8bc4\u6d4b\u5730\u5740<\/p>\n<h3>\u6837\u4f8b 1<\/h3>\n<pre><code>\u8f93\u5165\uff1agraph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1] \u8f93\u51fa\uff1a0 \u89e3\u91ca\uff1a\u79fb\u9664 0 \u7136\u540e\u53ea\u6709 1 \u88ab\u611f\u67d3\u3002 <\/code><\/pre>\n<h3>\u6837\u4f8b 2<\/h3>\n<pre><code>\u8f93\u5165\uff1agraph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1] \u8f93\u51fa\uff1a1 \u89e3\u91ca\uff1a\u79fb\u9664 1 \u7136\u540e\u53ea\u6709 0 \u88ab\u611f\u67d3\u3002 <\/code><\/pre>\n<h3>\u8003\u70b9<\/h3>\n<ul>\n<li>\u56fe\u8bba<\/li>\n<li>\u641c\u7d22<\/li>\n<\/ul>\n<h3>\u9898\u89e3<\/h3>\n<p>\u4ece\u53d7\u611f\u67d3\u7684\u9876\u70b9\uff08\u8d77\u59cb\u9876\u70b9\u7f16\u53f7\uff09\u5f00\u59cb dfs \u67d3\u8272\uff0c\u76f4\u5230\u627e\u4e0d\u5230\u53e6\u4e00\u4e2a\u53d7\u611f\u67d3\u7684\u9876\u70b9\u3002\u5982\u679c\u5f53\u524d\u9876\u70b9\u5df2\u5177\u6709\u5176\u4ed6\u989c\u8272\uff0c\u5c06\u5176\u6392\u9664\uff08\u8bbe\u7f6e\u4e3a-2 \uff09\u3002\u7b54\u6848\u662f\u51fa\u73b0\u6700\u591a\u6b21\u7684\u989c\u8272\u5bf9\u5e94\u7684\u53d7\u611f\u67d3\u7684\u9876\u70b9\u6216\u201c\u53d7\u611f\u67d3\u201d\u7684\u6700\u5c0f\u9876\u70b9\uff08\u5982\u679c\u6240\u6709\u9876\u70b9\u81f3\u5c11\u67d3\u8272 2 \u6b21\uff09\u3002<\/p>\n<pre><code>class Solution { public:     vector&lt;int&gt; col;                  void dfs(vector&lt;vector&lt;int&gt;&gt;&amp; g,unordered_set&lt;int&gt; &amp;hs,int v,int c) {         col[v] = col[v] == -1 ? c:-2;         for(int i = 0;i &lt; g.size();++i){             if(g[v][i] &amp;&amp; !hs.count(i) &amp;&amp; col[i] != c &amp;&amp; col[i] != -2) {                 dfs(g,hs,i,c);             }         }     }              int minMalwareSpread(vector&lt;vector&lt;int&gt;&gt;&amp; g, vector&lt;int&gt;&amp; in) {         unordered_map&lt;int,int&gt; hm;                 unordered_set&lt;int&gt; hs(in.begin(),in.end());         int n = g.size(), res, mx=0;         col.resize(n,-1);         for(auto v:in) dfs(g,hs,v,v);         for(auto v:col) {             if(v &gt;= 0) {                 if(++hm[v] &gt; mx) {                     res = v;                     mx = hm[v];                 }                 else if(hm[v] == mx) {                     res = min(res,v);                 }             }         }         if(hm.empty()) {              return *min_element(in.begin(),in.end());         }         return res;     } }; <\/code><\/pre>\n<p>\u66f4\u591a\u9898\u89e3\u53c2\u8003<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5317320\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LGA1150 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6240\u4ee5\u4e3a\u4ec0\u4e48\u628a C++ \u53d1\u5230 Java \u8282\u70b9\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5317321\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LGA1150 \u4e0d\u597d\u610f\u601d\uff0c\u653e\u9519\u4e86~                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e9a\u9a6c\u900a\u9762\u8bd5\u9898\uff1a\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/351856"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351856"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/351856\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351856"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}