标签:iostream code type ios style color namespace other mes
#include<cstring> #include<queue> #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int maxm=4e5+7; int pre[maxm],last[maxm],other[maxm],l; int n,m,ans; bool vis[maxm]; void add(int x,int y) { l++; pre[l]=last[x]; last[x]=l; other[l]=y; } void dfs(int x) { vis[x]=1; for(int p=last[x];p;p=pre[p]) { int v=other[p]; if(vis[v]) continue; dfs(v); } } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); add(x,y); add(y,x); } for(int i=1;i<=n;i++) { if(vis[i]==0) { dfs(i); ans++; } } printf("%d\n",m-n+ans); return 0; }
标签:iostream code type ios style color namespace other mes
原文地址:https://www.cnblogs.com/lihan123/p/11722717.html