标签:pre include 连通 always size void ffffff add code
边双连通分量
#include <bits/stdc++.h> using namespace std; struct littlestar{ int to; int nxt; }star[10010]; int head[10010],cnt; void add(int u,int v){ star[++cnt].to=v; star[cnt].nxt=head[u]; head[u]=cnt; } int st[5010],Top,num; int low[5010],dfn[5010],cur; int res[5010]; int kk[150][150]; int anss[5001]; void tarjan(int u,int fa) { bool flag=0; low[u]=dfn[u]=++cur; st[++Top]=u; for(int i=head[u];i;i=star[i].nxt){ int v=star[i].to; if(!dfn[v]){ tarjan(v,u); low[u]=min(low[u],low[v]); } else if(v!=fa || flag){ low[u]=min(low[u],dfn[v]); } else flag=1; } if(low[u]==dfn[u]){ num++; int tmp; do{ tmp=st[Top--]; res[tmp]=num; }while(tmp!=u); } } void find_leaf(int u){ for(int i=head[u];i;i=star[i].nxt){ int v=star[i].to; if(res[v]!=res[u]&&!kk[res[v]][res[u]]&&!kk[res[u]][res[v]]){ anss[res[v]]++; anss[res[u]]++; kk[res[v]][res[u]]=1; kk[res[u]][res[v]]=1; } } } int main () { for(int i=1;i<=n;++i)find_leaf(i); int ans=0; for(int i=1;i<=num;++i)if(anss[i]==1)ans++; cout<<(ans+1)/2; }
标签:pre include 连通 always size void ffffff add code
原文地址:https://www.cnblogs.com/kamimxr/p/11053539.html