BZOJ 4238 voltage problem-solving report

BZOJ 4238 Voltage

After consideration of an edge to be the answer, Ta after deleting the rest of the figure is a lot or a bipartite graph, that is not odd ring

Then an edge can be the answer, if and only if their own hand and not at all odd ring on the ring even.

Consider building a dfs tree, then a certain atavistic side of the ring.

Placed on the point, consider the direct process the two end points of the path covered by the throwback side edges, these points are in the ring, according to this parity ring up to make a difference.

But this only takes into account only a throwback situation on the edge of the ring, atavistic side at least we did not deal with two ring

Consider Category talk

  • If there are two different fathers pay back side of parity, a loop process is odd little ring, no matter how large or small odd odd ring ring has no effect
  • If the rings are odd, even then not on the large cross odd ring ring, did not affect
  • If the rings are even, apparently will not be the answer

But we also need to consider non-tree edge

If only one odd ring, then on the odd side of the ring is the answer

Otherwise, there are two sides to pay non-tree ring odd even necessarily constitute a large ring, the side of the tree does not become a non-answer.


Code:

#include <cstdio>
#include <cctype>
#include <map>
#include <algorithm>
#define ll long long
using std::max;
using std::min;
const int SIZE=1<<21;
char ibuf[SIZE],*iS,*iT;
//#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),iS==iT?EOF:*iS++):*iS++)
#define gc() getchar()
template <class T>
void read(T &x)
{
    x=0;char c=gc();
    while(!isdigit(c)) c=gc();
    while(isdigit(c)) x=x*10+c-'0',c=gc();
}
const int N=2e5+10;
int head[N],to[N<<2],Next[N<<2],cnt=1;
void add(int u,int v)
{
    to[++cnt]=v,Next[cnt]=head[u],head[u]=cnt;
}
int n,m,dep[N],jh[N],oh[N],vis[N<<2],jhc,ohc,ans;
void dfs(int now)
{
    for(int v,i=head[now];i;i=Next[i])
    {
        if(vis[i^1]) continue;
        v=to[i];
        vis[i]=1;
        if(!dep[v])
        {
            dep[v]=dep[now]+1;
            dfs(v);
            jh[now]+=jh[v];
            oh[now]+=oh[v];
        }
        else if((dep[now]-dep[v])&1)
            ++ohc,++oh[now],--oh[v];
        else
            ++jhc,++jh[now],--jh[v];
    }
}
int main()
{
    read(n),read(m);
    for(int u,v,i=1;i<=m;i++)
    {
        read(u),read(v);
        add(u,v),add(v,u);
    }
    for(int i=1;i<=n;i++)
        if(!dep[i])
            dep[i]=1,dfs(i);
    for(int i=1;i<=n;i++)
    {
        if(dep[i]==1) continue;
        if(!jhc) ans+=oh[i]==0;
        else if(jhc==1) ans+=jh[i]&&(oh[i]==0);
        else ans+=(jh[i]==jhc)&&(oh[i]==0);
    }
    printf("%d\n",ans+(jhc==1));
    return 0;
}

2019.6.26

Guess you like

Origin www.cnblogs.com/butterflydew/p/11090715.html
Recommended