P8436 \u3010\u6a21\u677f\u3011\u8fb9\u53cc\u8fde\u901a\u5206\u91cf<\/a><\/p>\n\u5728\u4e66\u5199\u4ee3\u7801\u7684\u65f6\u5019\u6709\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\u4f1a\u5728\u7a0b\u5e8f\u4e2d\u6807\u6ce8\u3002<\/p>\n
#include <iostream>\n#include <stack>\n#include <vector>\nusing namespace std;\nconst int maxn = 5e5 + 5;\n\nint n, m, cnt = 0;\nvector<pair<int, int> > G[maxn];\nvector<int> ans[maxn];\nint dfn[maxn], low[maxn];\nstack<int> stk;\n\nvoid tarjan(int x, int fa) {\n low[x] = dfn[x] = ++dfn[0];\n stk.push(x);\n for(auto i : G[x]) {\n int to = i.first, it = i.second; \n if (it == (fa ^ 1)) continue; \/\/\u5229\u7528\u4f4d\u8fd0\u7b97\u5224\u65ad\u91cd\u8fb9 \n if(!dfn[to]) {\n tarjan(to, it);\n low[x] = min(low[x], low[to]); \/\/dfn\u548clow\u4e0d\u8981\u641e\u9519 \n }\n else low[x] = min(low[x], dfn[to]);\n }\n if(dfn[x] == low[x]) {\n cnt++;\n ans[cnt].push_back(x);\n while(!stk.empty() && stk.top() != x) {ans[cnt].push_back(stk.top()), stk.pop();} \/\/\u51fa\u6808\u7684\u64cd\u4f5c\u9700\u8981\u6ce8\u610f \n stk.pop();\n }\n}\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n \/\/ freopen("AKIOI.in", "r", stdin);\n \/\/ freopen("AKIOI.out", "w", stdout);\n cin >> n >> m;\n for(int i = 1, u, v; i <= m; i++) {\n cin >> u >> v;\n G[u].push_back(make_pair(v, i * 2)); \/\/\u7ed9\u6bcf\u6761\u8fb9\u7f16\u53f7\u65b9\u4fbf\u53bb\u91cd \n G[v].push_back(make_pair(u, i * 2 + 1));\n }\n for(int i = 1; i <= n; i++) {\n if(!dfn[i]) tarjan(i, 0);\n }\n cout << cnt << "\\n";\n for(int i = 1; i <= cnt; i++) {\n cout << ans[i].size() << " ";\n for(auto j : ans[i]) cout << j << " ";\n cout << "\\n";\n }\n\n return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u524d\u7f6e\u77e5\u8bc6 \u56fe\u8bba\u76f8\u5173\u6982\u5ff5 \u5272\u70b9\u548c\u6865 \u5f3a\u8fde\u901a\u5206\u91cf \u70b9\u53cc\u8fde\u901a\u5206\u91cf \u5728\u4e00\u4e2a\u65e0\u5411\u56fe\u4e2d\uff0c\u82e5\u5220\u9664\u56fe\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u70b9\uff0c\u8fd9\u4e2a\u56fe\u8fd8\u80fd […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[27,28],"_links":{"self":[{"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/posts\/797"}],"collection":[{"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":1,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":798,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/posts\/797\/revisions\/798"}],"wp:attachment":[{"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ggapa.net:81\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}