【bzoj4272】筐子放球

看题解会的系列……

详细解释先坑着,以后补……

 1 #include<bits/stdc++.h>
 2 #define N 200005
 3 using namespace std;
 4 int head[N],ans=0,tot=0,cnt=0,n,m,vis[N];
 5 struct Edge{int u,v,next;}G[N<<1];
 6 inline void addedge(int u,int v){
 7     G[++tot].u=u;G[tot].v=v;G[tot].next=head[u];head[u]=tot;
 8     G[++tot].u=v;G[tot].v=u;G[tot].next=head[v];head[v]=tot;
 9 }
10 inline int read(){
11     int f=1,x=0;char ch;
12     do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
13     do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
14     return f*x;
15 }
16 void dfs(int u){
17     vis[u]=1;
18     for(int i=head[u];i;i=G[i].next,cnt++){
19         int v=G[i].v;
20         if(!vis[v])dfs(v);
21     }
22 }
23 int main(){
24     m=read();n=read();
25     for(int i=1;i<=m;i++){
26         int u=read(),v=read();
27         addedge(u,v);
28     }
29     for(int i=1;i<=n;i++){
30         if(!vis[i]){
31             cnt=0;dfs(i);
32             ans+=((cnt>>1)&1);
33         }
34     }
35     printf("%d
",ans);
36 }
原文地址:https://www.cnblogs.com/zcysky/p/6879302.html