華華和月月逛公園(牛客小白賽)
阿新 • • 發佈:2019-04-08
esp space return include isp while none == gis
https://ac.nowcoder.com/acm/contest/392/I
#include <bits/stdc++.h> using namespace std; #define re register #define ll long long const int maxn=1e5+10; void read(int &a) { a=0; int d=1; char ch; while(ch=getchar(),ch>‘9‘||ch<‘0‘) if(ch==‘-‘) dView Code=-1; a=ch-‘0‘; while(ch=getchar(),ch>=‘0‘&&ch<=‘9‘) a=a*10+ch-‘0‘; a*=d; } void write(int x) { if(x<0) putchar(45),x=-x; if(x>9) write(x/10); putchar(x%10+‘0‘); } int head[maxn],low[maxn],dfn[maxn],num,cnt,ans; struct note {int v,next; }q[6*maxn]; void add(int u,int v) { q[++num].next=head[u]; q[num].v=v; head[u]=num; } void tarjan(int x,int fa) { low[x]=dfn[x]=++cnt; for(re int i=head[x];i;i=q[i].next) { int v=q[i].v; if(v==fa) continue; if(!dfn[v]) { tarjan(v,x); low[x]=min(low[v],low[x]); if(low[v]>dfn[x]) ans++; } else low[x]=min(low[x],dfn[v]); } } int main() { int n,m; read(n); read(m); for(re int i=0;i<m;i++) { int a,b; read(a); read(b); add(a,b); add(b,a); } for(re int i=1;i<=n;i++) { if(!dfn[i]) tarjan(i,0); } write(m-ans); return 0; }
華華和月月逛公園(牛客小白賽)