标签:sync als efi nsis pointer NPU sar padding incr
求简单环,即求点=边数的点双分量,加上判断点和边的模板即可
const int maxm = 1e5+5; int head[maxm<<1], edgecnt, dfn[maxm], low[maxm], bcc_cnt, bccnum[maxm], dfs_clock, s[maxm], top; vector<int> bcc[maxm], ans; struct edge{ int u, v, nex; } edges[maxm<<1]; void addedge(int u, int v) { edges[++edgecnt].u = u; edges[edgecnt].v = v; edges[edgecnt].nex = head[u]; head[u] = edgecnt; } void tarjan(int u, int fa) { dfn[u] = low[u] = ++dfs_clock; int child = 0, v; for(int i = head[u]; i; i = edges[i].nex) { v = edges[i].v; if(v == fa) continue; if(!dfn[v]) { s[++top] = i; tarjan(v, u); low[u] = min(low[u], low[v]); if(low[v] >= dfn[u]) { bcc[++bcc_cnt].clear(); int vet = 0; while(true) { int num = s[top--]; bcc[bcc_cnt].push_back((num+1)/2); if(bccnum[edges[num].u] != bcc_cnt) { vet++; bccnum[edges[num].u]=bcc_cnt; } if(bccnum[edges[num].v] != bcc_cnt) { vet++; bccnum[edges[num].v]=bcc_cnt; } if(edges[num].u == u && edges[num].v == v) break; } if(vet == bcc[bcc_cnt].size()) for(int i = 0; i < bcc[bcc_cnt].size(); ++i) ans.push_back(bcc[bcc_cnt][i]); } } else if(dfn[v] < dfn[u]){ s[++top] = i; low[u] = min(low[u], dfn[v]); } } } void run_case() { int n, m, u, v; cin >> n >> m; for(int i = 1; i <= m; ++i) { cin >> u >> v; addedge(u, v), addedge(v, u); } for(int i = 1; i <= n; ++i) if(!dfn[i]) tarjan(i, -1); sort(ans.begin(), ans.end()); cout << ans.size() << "\n"; for(int i : ans) cout << i << " "; } int main() { ios::sync_with_stdio(false), cin.tie(0); run_case(); return 0; }
codeforces 962 F Simple Cycles Edges
标签:sync als efi nsis pointer NPU sar padding incr
原文地址:https://www.cnblogs.com/GRedComeT/p/12259130.html