T103481 【模板】割邊
阿新 • • 發佈:2020-08-05
#include <bits/stdc++.h> #define inf 2333333333333333 #define N 3000010 #define p(a) putchar(a) #define For(i,a,b) for(int i=a;i<=b;++i) //by war //2020.8.4 using namespace std; int n,m,x,y,cnt,ans; int dfn[N],low[N]; bool vis[N]; struct node{ int n; node *next; }*e[N]; void in(int &x){int y=1;char c=getchar();x=0; while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();} while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();} x*=y; } void o(int x){ if(x<0){p('-');x=-x;} if(x>9)o(x/10); p(x%10+'0'); } void push(int x,int y){ node*p; p=new node(); p->n=y; if(e[x]==0) e[x]=p; else{ p->next=e[x]->next; e[x]->next=p; } } void tarjan(int x,int fa){ dfn[x]=low[x]=++cnt; vis[x]=1; for(node *i=e[x];i;i=i->next){ if(i->n==fa) continue; if(!dfn[i->n]){ tarjan(i->n,x); low[x]=min(low[x],low[i->n]); if(low[i->n]>dfn[x]) ans++; } else if(vis[i->n]) low[x]=min(low[x],dfn[i->n]); } } int main(){ in(n);in(m); For(i,1,m){ in(x);in(y); push(x,y); push(y,x); } For(i,1,n) if(!dfn[i]) tarjan(i,i); o(ans);p('\n'); return 0; }