记录编号 | 199642 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 游历校园 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 1.760 s | ||
提交时间 | 2015-10-27 08:00:48 | 内存使用 | 28.63 MiB | ||
#include<cstdio> #include<deque> #include<iostream> using namespace std; const int SIZEN=100010,SIZEM=500010; int N,M,d[SIZEN]={0},tot=0; bool visit[SIZEN]={0}; deque<int> s[SIZEN]; class miku { public: int fr,to; bool t; miku(){} miku(int a,int b,int c) { fr=a,to=b,t=c; } }E[SIZEM*2]; void add(int fr,int to) { s[fr].push_back(tot); E[tot++]=miku(fr,to,0); s[to].push_back(tot); E[tot++]=miku(to,fr,0); d[fr]++;d[to]++; } void read() { scanf("%d%d",&N,&M); int fr,to; for(int i=1;i<=M;i++) { scanf("%d%d",&fr,&to); add(fr,to); } } int nowans=0; int dfs(int x) { visit[x]=1; if(d[x]%2==1) { nowans++; } int ans=1; for(int i=0;i<s[x].size();i++) { miku v=E[s[x][i]]; if(!visit[v.to]) ans+=dfs(v.to); } return ans; } void work() { int ans=0; for(int i=1;i<=N;i++) { if(!visit[i]) { nowans=0; int now=dfs(i); if(now!=1) { ans++; if(nowans>=2) ans+=(nowans-2)/2; } } } ans--; printf("%d",ans); } int main() { freopen("sent.in","r",stdin); freopen("sent.out","w",stdout); read(); work(); return 0; }