标签:ota getchar names read mes git rip 联合国 des
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #define MAXN 150010 #define REP(i,k,n) for(int i=k;i<=n;i++) #define in(a) a=read() using namespace std; inline int read(){ int f=1,x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch==‘-‘) f=-1; for(;isdigit(ch);ch=getchar()) x=x*10+ch-‘0‘; return x*f; } int n,m,cnt,ans; int dfn[MAXN],low[MAXN]; int total=0,head[MAXN],nxt[MAXN<<1],to[MAXN<<1]; inline void adl(int a,int b){ total++; to[total]=b; nxt[total]=head[a]; head[a]=total; return ; } inline void tarjan(int u,int f){ low[u]=dfn[u]=++cnt; for(int e=head[u];e;e=nxt[e]){ if(!dfn[to[e]] && to[e]!=f){ tarjan(to[e],u); low[u]=min(low[to[e]],low[u]); if(low[to[e]]>dfn[u]) ans++; } else if(dfn[to[e]]<low[u] && to[e]!=f) low[u]=dfn[to[e]]; } return ; } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ if(n==0 && m==0) return 0; total=0; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(head,0,sizeof(head)); cnt=ans=0; int a,b; REP(i,1,m){ in(a);in(b); adl(a,b); adl(b,a); } tarjan(1,0); cout<<ans<<endl; } }
标签:ota getchar names read mes git rip 联合国 des
原文地址:https://www.cnblogs.com/jason2003/p/9702994.html