HDU 5765 Bonds

求一个无向连通图中每条边在极小割中出现的次数。
n≤20,m≤n(n-1)/2.

关于极小割:
s.t.没有任何一个可行割是其子集
极小割边集的定义下割边集恰好会将原图分成两块。

接下来要处理的是将两个块之间的边加一。
这部分可以处理成将左块中的边减一,右块中的边减一,整体加一。
操作变成了把一个块的边加权值的操作。考虑一条边表达成形如 0..010..010..0的形式,它在所有块中的权值总和,便是求一遍把这个形式作为子集的集合的权值和,求一遍高维前缀和就可以了。

高维前缀和:)

#include<set>
#include<ctime>
#include<queue>
#include<cstdio>
#include<bitset>
#include<cctype>
#include<bitset>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf (1<<30)
#define INF (1ll<<62)
#define fi first
#define se second
#define rep(x,s,t) for(int x=s,t_=t;x<t_;x++)
#define per(x,s,t) for(int x=t-1,s_=s;x>=s_;x--)
#define prt(x) cout<<#x<<":"<<x<<" "
#define prtn(x) cout<<#x<<":"<<x<<endl
#define pc(x) putchar(x)
#define pb(x) push_back(x)
#define lb(x) ((x)&(-x))
#define hash asfmaljkg
#define rank asfjhgskjf
#define y1 asggnja
#define y2 slfvm
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
template<class T>void sc(T &x){
    int f=1;char c;x=0;
    while(c=getchar(),c<48)if(c=='-')f=-1;
    do x=x*10+(c^48);
    while(c=getchar(),c>47);
    x*=f;
}
template<class T>void nt(T x){
    if(!x)return;
    nt(x/10);
    pc(x%10+'0');
}
template<class T>void pt(T x){
    if(x<0)pc('-'),x=-x;
    if(!x)pc('0');
    else nt(x);
}
template<class T>void ptn(T x){
    pt(x);putchar('\n');
}
template<class T>void pts(T x){
    pt(x);putchar(' ');
}
template<class T>inline void Max(T &x,T y){if(x<y)x=y;}
template<class T>inline void Min(T &x,T y){if(x>y)x=y;}

const int maxn=20;
int n,m;
int u[maxn*maxn>>1],v[maxn*maxn>>1];
int can[1<<maxn];
int b[1<<maxn];
int sum[1<<maxn];
int q[1<<maxn];
bool chk(int x){
    if(x==lb(x))return true;
    int y=x;
    while(y){
        int k=lb(y);
        if(can[x^k]&&(b[k]&(x^k)))return true;
        y^=k;
    }return false;
}
void solve(){
    sc(n);sc(m);
    memset(sum,0,1<<n+2);
    memset(b,0,1<<n+2);
    rep(i,0,m){
        sc(u[i]);sc(v[i]);
        b[1<<u[i]]|=1<<v[i];
        b[1<<v[i]]|=1<<u[i];
    }
    rep(i,1,1<<n)b[i]=b[i^lb(i)]|b[lb(i)];
    rep(i,1,1<<n)can[i]=chk(i);

    int all=0,nn=(1<<n)-1;
    rep(i,0,1<<n){
        if(can[i]&&can[nn^i]){
            all++;
            sum[i]--;
        }
    }
    all>>=1;
    rep(i,0,n)
        rep(j,0,1<<n)
            if(!(j&(1<<i)))
                sum[j]+=sum[j|1<<i];

    rep(i,0,m){
        if(i==m-1)ptn(all+sum[1<<u[i]|1<<v[i]]);
        else pts(all+sum[1<<u[i]|1<<v[i]]);
    }
}

int main(){
//  freopen("pro.in","r",stdin);
//  freopen("chk.out","w",stdout);
    int cas;sc(cas);
    rep(kase,1,cas+1){
        printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}

btw.比赛时看见别人直接更新两个块之间的边, O(n2n+ansiK) ,强势过了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值