{"id":76,"date":"2022-12-14T13:11:24","date_gmt":"2022-12-14T05:11:24","guid":{"rendered":"https:\/\/www.vcoco.top\/?p=76"},"modified":"2022-12-14T13:13:25","modified_gmt":"2022-12-14T05:13:25","slug":"%e4%bf%a1%e5%a5%a5%e4%b8%80%e6%9c%ac%e9%80%9a-%e5%8d%95%e8%af%8d%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"https:\/\/www.vcoco.top\/index.php\/2022\/12\/14\/%e4%bf%a1%e5%a5%a5%e4%b8%80%e6%9c%ac%e9%80%9a-%e5%8d%95%e8%af%8d%e6%b8%b8%e6%88%8f\/","title":{"rendered":"\u4fe1\u5965\u4e00\u672c\u901a \u5355\u8bcd\u6e38\u620f"},"content":{"rendered":"\n<p>\u5927\u5bb6\u4f19\u90fd\u7528\u5e76\u67e5\u96c6\uff0c\u6211\u5c31\u7528\u4e0b\u6b27\u62c9\u8def\u5f84\u7684 dfs \u6765\u5224\u65ad\u8fde\u901a\u6027\u5427<\/p>\n\n\n\n<p>\u8fd9\u9898\u7c7b\u4f3c\uff1aspoj2885 \u5355\u8bcd\u73af<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b97\u6cd5\u5206\u6790\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u628a\u5355\u8bcd\u770b\u6210\u4e00\u6761\u8fb9\uff0c\u6bcf\u8f93\u5165\u4e00\u4e2a\u5355\u8bcd\u770b\u6210\u4ece\u9996\u5b57\u6bcd\u5230\u5c3e\u5b57\u6bcd\u7684\u4e00\u6761\u8fb9\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u901a\u8fc7\u6b27\u62c9\u8def\u5f84\u7684\u5206\u6790\u65b9\u6cd5\u5224\u65ad\u662f\u5426\u5b58\u5728\u4ece\u4e00\u4e2a\u70b9\u51fa\u53d1\u8fde\u63a5\u6240\u6709\u8fb9\u7684\u8def\u5f84\uff08\u5373\u6b27\u62c9\u8def\u5f84\uff09\uff0c\u6ce8\u610f\uff1a\u8fd9\u91cc\u4e0d\u4e00\u5b9a\u662f\u56de\u8def\uff0c\u80fd\u8fde\u63a5\u6240\u6709\u5355\u8bcd\u5373\u53ef<\/li>\n\n\n\n<li>\u56e0\u4e3a\u662f\u6709\u5411\u8fb9\u5f00\u4e24\u4e2a\u5ea6\u6570\u6570\u7ec4\uff0c<code>din<\/code>\u548c<code>dout<\/code>\uff0c\u6b27\u62c9\u8def\u5f84\u9664\u4e86\u7ec8\u70b9\u548c\u8d77\u70b9\u5916\u8981\u6c42\u5176\u4ed6\u6bcf\u4e2a\u70b9<code>\u5165\u5ea6=\u51fa\u5ea6<\/code>\uff0c\u5224\u65ad\u6bcf\u4e2a\u70b9\u7684\u5165\u5ea6\u4e0d\u7b49\u4e8e\u51fa\u5ea6\u6709\u4e09\u79cd\u53ef\u80fd\uff1a<code>\u8d77\u70b9\u3001\u7ec8\u70b9\u3001\u4e0d\u5b58\u5728\u6b27\u62c9\u8def\u5f84\u3002<\/code><\/li>\n\n\n\n<li>\u503c\u5f97\u6ce8\u610f\u7684\u662f\u5982\u679c\u8fd9\u4e9b\u8fb9\u4e2d\u5ea6\u6570\u5df2\u7ecf\u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u5373\u8d77\u70b9\u6216\u7ec8\u70b9\u4e2a\u6570\u4e0d\u6b62\u4e00\u4e2a\uff0c\u6216\u8d77\u70b9\u6570!=\u7ec8\u70b9\u6570\u7684\u65f6\u5019\u90fd\u662f\u5c5e\u4e8e\u4e0d\u5b58\u5728\u6b27\u62c9\u8def\u5f84\u7684\u60c5\u51b5\u3002\u56e0\u6b64\u8981\u5148\u5224\u65ad\uff0c\u518ddfs\u3002\u56e0\u4e3adfs\u5728\u8981\u4fdd\u8bc1\u6b63\u786e\u6027\u7684\u524d\u63d0\u4e0b\u53ea\u80fd\u5224\u65ad\u662f\u5426\u8fde\u901a\uff0c\u5373\u6700\u540e <code>cnt == m ? \u8fde\u901a : \u4e0d\u8fde\u901a<\/code>\u3002\u56e0\u4e3a\u4e0d\u5b58\u5728\u6b27\u62c9\u8def\u5f84\u65f6\u4ea6\u53ef\u80fd cnt = m\uff0c<\/li>\n<\/ul>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong>\uff1a\u6b27\u62c9\u8def\u5f84\u9664\u4e86\u8fde\u901a\u6027\u90fd\u7528<code>din<\/code>\u548c<code>dout<\/code>\u6570\u7ec4\u6765\u5224\u65ad\uff0c\u8fde\u901a\u6027\u7528<code>dfs<\/code>\u6765\u5224\u65ad\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nconst int N = 1010,M=100010;\n\nint e&#91;M],ne&#91;M],h&#91;N],idx;\nint n,m;\nint din&#91;N],dout&#91;N];\nint cnt;\n\nvoid add(int a, int b)  \/\/ \u6dfb\u52a0\u4e00\u6761\u8fb9a-&gt;b\n{\n    e&#91;idx] = b, ne&#91;idx] = h&#91;a], h&#91;a] = idx ++ ;\n}\n\nvoid dfs(int u)\n{\n    for(int &amp;i=h&#91;u];~i;)\n    {\n        int j=e&#91;i];\n        i=ne&#91;i];\n        dfs(j);\n\n        cnt++;\n    }\n}\n\nint main()\n{\n    char str&#91;N];\n    int T; cin&gt;&gt;T;\n    while(T--)\n    {\n        memset(h, -1, sizeof h);\n        idx=cnt=0;\n        memset(din,0,sizeof din);\n        memset(dout,0,sizeof dout);\n        cin&gt;&gt;m;\n        for(int i=0;i&lt;m;i++)\n        {\n            scanf(\"%s\",str);\n            int a=str&#91;0]-'a', b=str&#91;strlen(str)-1]-'a';\n            add(a,b);\n            din&#91;b]++, dout&#91;a]++;\n        }\n\n        int start=0,s=0,e=0;\n        while(din&#91;start]+dout&#91;start]==0) start++; \/\/\u9632\u6b62\u662f\u56de\u8def\u7684\u60c5\u51b5\n        for(int i=start;i&lt;26;i++)\n            if(din&#91;i]!=dout&#91;i])\n            {\n                if(dout&#91;i]==din&#91;i]+1) \/\/\u5b58\u5728\u4e00\u4e2a\u8d77\u70b9\n                {\n                    start=i;\n                    s++;\n                }\n                else if(din&#91;i]==dout&#91;i]+1) e++; \/\/\u5b58\u5728\u4e00\u4e2a\u7ec8\u70b9\n                else\n                {\n                    s=10000;\n                    break;\n                }\n            }\n\n        if(s&gt;1||e&gt;1||s!=e) \/\/\u4e0d\u5b58\u5728\u6b27\u62c9\u8def\u5f84\n        {\n            puts(\"The door cannot be opened.\");\n            continue;\n        }\n\n        dfs(start);\n\n        if(cnt&lt;m) puts(\"The door cannot be opened.\");\n        else puts(\"Ordering is possible.\");\n    }\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u4f19\u90fd\u7528\u5e76\u67e5\u96c6\uff0c\u6211\u5c31\u7528\u4e0b\u6b27\u62c9\u8def\u5f84\u7684 dfs \u6765\u5224\u65ad\u8fde\u901a\u6027\u5427 \u8fd9\u9898\u7c7b\u4f3c\uff1aspoj2885 \u5355\u8bcd\u73af \u7b97\u6cd5\u5206\u6790\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[30,55,49,54],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-mess","tag-dfs","tag-55","tag-49","tag-54"],"_links":{"self":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":2,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":79,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/79"}],"wp:attachment":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}