{"id":70,"date":"2023-03-06T21:21:55","date_gmt":"2023-03-06T13:21:55","guid":{"rendered":"https:\/\/solost.cn\/?p=70"},"modified":"2023-03-06T21:21:55","modified_gmt":"2023-03-06T13:21:55","slug":"157","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=70","title":{"rendered":"AtCoder Beginner Contest 292- E &#8211; Transitivity"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image-6.png\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>solution<\/h2>\n<p>\u8fd9\u9053\u9898\u76ee\u7684\u5927\u610f\u662f\u7ed9\u4e00\u4e2a\u6709\u5411\u56fe\uff0c\u7136\u540e\u95ee\u4f60\u4ecea-b,b-c\u4e14a-c\u8fde\u4e00\u6761\u8fb9\u4e14\u8ddd\u79bb\u7b49\u4e8e1\u7684\u6761\u6570\uff0c\u6b63\u9762\u6765\u505a\u8fd9\u9053\u9898\u6709\u4e00\u5b9a\u7684\u96be\u5ea6\uff0c\u8fd9\u4e2a\u6570\u8d77\u6765\u592a\u9ebb\u70e6\uff0c\u53ef\u4ee5\u8f6c\u6362\u601d\u8def\uff0c\u4f8b\u5982\uff0c\u628a\u4ed6\u6240\u6709\u7684\u4ece\u5f53\u524d\u70b9\u5230\u53ef\u4ee5\u5230\u8fbe\u7684\u70b9\u7684\u6570\u76ee\u5168\u90e8\u6570\u51fa\u6765\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4ecea-b\u8ddd\u79bb\u4e3a1\uff0c2\uff0c3\uff0c4.....n\u7684\u6240\u6709\u60c5\u51b5\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u662f\u4ecea-b-c\u6240\u4ee5\u957f\u5ea6\u81f3\u5c11\u4e3a2\uff0c\u90a3\u6211\u4eec\u8ba1\u7b97\u7684\u65f6\u5019\u8ba1\u7b97\u4e86\u957f\u5ea6\u4e3a1\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u7ed9\u51fa\u8fb9\u7684\u65f6\u5019\u5c31\u662f\u957f\u5ea6\u4e3a1\uff0c\u5373a-b\u957f\u5ea6\u80af\u5b9a\u662f1\uff0c\u6240\u4ee5\u6211\u4eec\u5220\u53bbm\u5373\u662f\u6240\u6709\u7684\u60c5\u51b5\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int, int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nint n, m;\nvector&lt;int&gt; v[20100];\n\/\/ int v[2010][2010];\nmap&lt;int, int&gt; vis;\nint res, ans;\nint dfs(int u)\n{\n    vis[u] = 1;\n    for(auto x : v[u]){\n        if(!vis[x]){\n            res++;\n            vis[x] = 1;\n            dfs(x);\n        }\n    }\n    return res;\n}\n\nvoid solve()\n{\n    cin &gt;&gt; n &gt;&gt; m;\n    for (int i = 1; i &lt;= m; i++) {\n        int a, b;\n        cin &gt;&gt; a &gt;&gt; b;\n            v[a].push_back(b);\n    }\n    for (int i = 1; i &lt;= n; i++) {\n        dfs(i);\n        vis.clear();\n    }\n    cout &lt;&lt; res - m &lt;&lt; endl;\n}\nint main()\n{\n    IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>solution \u8fd9\u9053\u9898\u76ee\u7684\u5927\u610f\u662f\u7ed9\u4e00\u4e2a\u6709\u5411\u56fe\uff0c\u7136\u540e\u95ee\u4f60\u4ecea-b,b-c\u4e14a-c\u8fde\u4e00\u6761\u8fb9\u4e14\u8ddd\u79bb\u7b49\u4e8e1\u7684\u6761\u6570\uff0c\u6b63\u9762\u6765\u505a\u8fd9\u9053\u9898\u6709\u4e00\u5b9a\u7684\u96be\u5ea6\uff0c\u8fd9\u4e2a\u6570\u8d77\u6765\u592a\u9ebb\u70e6\uff0c\u53ef\u4ee5\u8f6c\u6362\u601d\u8def\uff0c\u4f8b\u5982\uff0c\u628a\u4ed6\u6240\u6709\u7684\u4ece\u5f53\u524d\u70b9\u5230\u53ef\u4ee5\u5230\u8fbe\u7684\u70b9\u7684\u6570\u76ee\u5168\u90e8\u6570\u51fa\u6765\uff0c\u90a3\u4e48\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4ecea-b\u8ddd\u79bb\u4e3a1\uff0c2\uff0c3\uff0c4.....n\u7684\u6240\u6709\u60c5\u51b5\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u662f\u4ecea-b-c\u6240\u4ee5\u957f\u5ea6\u81f3\u5c11\u4e3a2\uff0c\u90a3\u6211\u4eec\u8ba1\u7b97\u7684\u65f6\u5019\u8ba1\u7b97\u4e86\u957f\u5ea6\u4e3a1\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u7ed9\u51fa\u8fb9\u7684\u65f6\u5019\u5c31\u662f\u957f\u5ea6\u4e3a1\uff0c\u5373a-b\u957f\u5ea6\u80af\u5b9a\u662f1\uff0c\u6240\u4ee5\u6211\u4eec\u5220\u53bbm\u5373\u662f\u6240\u6709\u7684\u60c5\u51b5\u3002 #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;vector&gt; using namespace std; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[24,30],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-solution","tag-dfs","tag-30"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}