{"id":432,"date":"2024-05-02T15:16:27","date_gmt":"2024-05-02T07:16:27","guid":{"rendered":"https:\/\/seanxd.com\/?p=432"},"modified":"2024-05-02T15:16:30","modified_gmt":"2024-05-02T07:16:30","slug":"zerojudge-a290","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a290\/","title":{"rendered":"ZeroJudge A290: Training\uff5eTuring"},"content":{"rendered":"\n\n\n<p class=\"\">\u4fd7\u8a71\u8aaa\uff1a\u300c\u689d\u689d\u5927\u8def\u901a\u7f85\u99ac\u300d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7b46\u8f38\u5165\u6709\u5169\u500b\u6b63\u6574\u6578 N \u548c M (N &lt;= 800\uff0cM &lt;= 10000)<br>\u4ee3\u8868\u6709 N \u500b\u57ce\u5e02 M \u689d\u9053\u8def\uff01<br>\u8acb\u6ce8\u610f\uff0c\u9053\u8def\u662f\u6709\u65b9\u5411\u6027\u7684\uff01<br>\u63a5\u4e0b\u4f86\u6709 M \u884c\uff0c \u6bcf\u884c\u6709 2 \u500b\u6b63\u6574\u6578 a \u548c b (1 &lt;= a\uff0cb &lt;= N)<br>\u4ee3\u8868 a \u57ce\u5e02 \u53ef\u4ee5\u5230 b \u57ce\u5e02<br>\u6700\u5f8c\u4e00\u884c\u6709\u5169\u500b\u6b63\u6574\u6578 A \u548c B (1 &lt;= A\uff0cB &lt;= N)<\/td><td>\u5982\u679c A \u57ce\u5e02 \u53ef\u4ee5\u5230\u9054 B \u57ce\u5e02\uff0c<br>\u8acb\u8f38\u51fa\u300cYes!!!\u300d<br>\u4e0d\u884c\u8acb\u8f38\u51fa\u300cNo!!!\u300d<\/td><\/tr><tr><td>8  32<br>7  4<br>2  5<br>7  5<br>3  7<br>2  1 <br>2  2<br>2  4<br>4  4<br>4  7<br>8  5<br>7  5<br>5  2<br>6  7<br>7  5<br>8  8<br>4  7<br>6  3<br>4  1<br>4  4<br>8  7<br>3  4<br>2  6<br>6  1<br>6  8<br>4  5<br>7  5<br>6  6<br>4  4<br>2  6<br>5  3<br>7  4<br>1  3<br>1  3<\/td><td>Yes!!!<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge A290 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528 <strong>Map&lt;int, vector&lt;int>> \u4f86\u5b58\u53d6\u54ea\u4e9b\u57ce\u5e02\u53ef\u4ee5\u901a\u5f80\u54ea\u4e9b\u57ce\u5e02<\/strong>\uff0c\u4e26\u4e14\u7528 <strong>BFS \u7684\u65b9\u5f0f\u5c0b\u627e\u54ea\u4e9b\u57ce\u5e02\u53ef\u4ee5\u901a\u5f80\u54ea\u4e9b\u57ce\u5e02<\/strong>\uff0c\u6bcf\u6b21\u9032\u5230 BFS \u7684\u6642\u5019\u9700\u8981\u5224\u65b7\u54ea\u4e9b\u57ce\u5e02\u5df2\u7d93\u88ab Push_Back \u5230\u4e0b\u4e00\u6b21\u7684\u8d77\u9ede\u4e86\uff0c\u5982\u679c\u5df2\u7d93\u88ab Push_Back \u904e\u7684\u8d77\u9ede\u5c31\u4e0d\u518d Push_Back\u3002<\/p>\n\n\n\n<p class=\"\">\u5982\u679c\u8d70\u5230\u7d42\u9ede\u57ce\u5e02\u5c31\u53ef\u4ee5\u8f38\u51fa Yes\uff0c\u5982\u679c\u9047\u5230\u8d77\u9ede\u7684\u9663\u5217\u9577\u5ea6\u70ba 0 \u5c31\u4ee3\u8868\u6c38\u9060\u8d70\u4e0d\u5230\u8f38\u51faNo\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a290\" target=\"_blank\" rel=\"noopener\">ZeroJudge A290: \u65b0\u624b\u8a13\u7df4\u7cfb\u5217 ~ \u5716\u8ad6<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-plain\"><code>#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nmap&lt;int, vector&lt;int&gt;&gt;MAP;\nint N, M, start, finish;\n\nvoid BFS(vector&lt;int&gt;start)\n{\n    if (start.size() == 0)\n    {\n        cout &lt;&lt; &quot;No!!!\\n&quot;;\n        return;\n    }\n    vector&lt;int&gt;newStart;\n    map&lt;int, int&gt;appear;\n    for (int i = 0; i&lt;start.size(); i++)\n    {\n        vector&lt;int&gt;step = MAP[start[i]];\n        for (int j = 0; j&lt;step.size(); j++)\n        {\n            if (step[j] == finish)\n            {\n                cout &lt;&lt; &quot;Yes!!!\\n&quot;;\n                return;\n            }\n            if (appear[step[j]] == 0)\n            {\n                appear[step[j]]++;\n                newStart.push_back(step[j]);\n            }\n        }\n    }\n    BFS(newStart);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    while (cin &gt;&gt; N &gt;&gt; M)\n    {\n        MAP.clear();\n        for (int i = 0; i&lt;M; i++)\n        {\n            int a, b;\n            cin &gt;&gt; a &gt;&gt; b;\n            MAP[a].push_back(b);\n        }\n        cin &gt;&gt; start &gt;&gt; finish;\n        vector&lt;int&gt;v;\n        v.push_back(start);\n        BFS(v);\n    }\n}\n\n\/\/ZeroJudge A290\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4fd7\u8a71\u8aaa\uff1a\u300c\u689d\u689d\u5927\u8def\u901a\u7f85\u99ac\u300d \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38\u5165 \u7bc4\u4f8b\u8f38\u51fa EOF \u8f38\u5165\uff0c\u6bcf\u7b46\u8f38\u5165\u6709\u5169\u500b\u6b63\u6574\u6578 N \u548c M (N [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[29],"tags":[30,14,20,8,9],"class_list":["post-432","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-bfs","tag-map","tag-20","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=432"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/432\/revisions"}],"predecessor-version":[{"id":434,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/432\/revisions\/434"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}