标签:out date count int add mis printf mit 欧拉路径
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define esp 0.00000000001 const int N=1e5+10,M=1e6+10,inf=1e9; const ll INF=1e18+10; int n,m; int fa[N],du[N],flag[N],mark[N],hh[N]; int Find(int x) { return fa[x]==x?x:fa[x]=Find(fa[x]); } void update(int u,int v) { int x=Find(u); int y=Find(v); if(x!=y) { fa[x]=y; } } void init() { for(int i=0;i<N;i++) fa[i]=i; memset(flag,0,sizeof(flag)); memset(du,0,sizeof(du)); memset(mark,0,sizeof(mark)); memset(hh,0,sizeof(hh)); } int main() { while(~scanf("%d%d",&n,&m)) { init(); for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); update(u,v); du[u]++; du[v]++; hh[u]=1; hh[v]=1; } int ans=0,sum=0; for(int i=1;i<=n;i++) { if(!hh[i])continue; int x=Find(i); du[i]%=2; sum+=du[i]; if(!flag[x]) { ans++; flag[x]=1; } if(du[i]==1&&flag[x]&&!mark[x]) { ans--; mark[x]=1; } } printf("%d\n",ans+sum/2); } return 0; }
标签:out date count int add mis printf mit 欧拉路径
原文地址:http://www.cnblogs.com/jhz033/p/6114959.html