noi.ac # 712 leveling

analysis

The boat as a point

As a leveling edge

A communication block found is larger than the number of answers parity influence of the n-1 sides of the communication block

So disjoint-set to maintain

Code

#include<bits/stdc++.h>
using namespace std;
int fa[200100],siz[200100],is[200100],Ans,n,m;
inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
int main(){
    int i,j,k;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)fa[i]=i,siz[i]=1;
    for(i=1;i<=m;i++){
      int x,y;
      scanf("%d%d",&x,&y);
      if(sf(x)!=sf(y)){
          siz[sf(y)]+=siz[sf(x)];
          is[sf(y)]^=is[sf(x)];
          fa[sf(x)]=sf(y);
      }else is[sf(x)]^=1;
    }
    for(i=1;i<=n;i++)if(sf(i)==i)Ans+=siz[i]-(is[i]?0:1);
    cout<<Ans;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/yzxverygood/p/11612335.html