标签:str while txt set ring span 需要 ems 欧拉路径
Ant Trip
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; int n,m,fa[100040],de[100004],sum[100040],num[100004]; void init(){ memset(de,0,sizeof(de)); memset(sum,0,sizeof(sum)); memset(num,0,sizeof(num)); rep(i,1,n) fa[i]=i; } int find(int x){ if(fa[x]==x) return x; else return fa[x]=find(fa[x]); } int main(){ freopen("1.txt","r",stdin) while(~scanf("%d%d",&n,&m)){ int s=0; init(); rep(i,1,m){ int a,b; scanf("%d%d",&a,&b); ++de[a]; ++de[b]; a=find(a); b=find(b); if(a!=b) fa[a]=b; } rep(i,1,n){ if(de[i]&1) sum[find(i)]++; num[find(i)]++; } rep(i,1,n){ if(num[i]==0 || num[i]==1) continue; else if(sum[i]==0) ++s; else s+=(sum[i]/2); } printf("%d\n",s); } return 0; }
标签:str while txt set ring span 需要 ems 欧拉路径
原文地址:https://www.cnblogs.com/handsome-zlk/p/10189751.html