HDU5765 Bonds 最小割极
http://acm.hdu.edu.cn/showproblem.php?pid=5765
题意:无向连通图,问每条边在几个最小割极上
思路:用位压形式,表示边的关系。g[1<<i]=1<<x 表示第i个点与哪几个点相连。然后,处理出每种点集和哪些点相连。每个点构成一个连通图,所以枚举当前点集,可以得到所有连通图的点集,计算出数量,用高维前缀和处理所有包含i点的连通块
ans=(所有连通块-同时包含(i,j)的连通块数目)/2 应为以(i,j)为割边的连通块,删除该边以后,数量加倍,所以除2
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <conio.h>
#define clc(a,b) memset(a,b,sizeof(a))
#include <bits/stdc++.h>
const int maxn = ;
const int inf=0x3f3f3f3f;
const double pi=acos(-);
typedef long long LL;
using namespace std;
//const LL MOD = 1e9+7;
void fre(){freopen("in.txt","r",stdin);}
inline int lb(int x){return x&(-x);}
const int N=<<; int g[N],a[N],u[],v[];
bool vis[N];
int sum[N];
int main(){
int T;
scanf("%d",&T);
for(int cas=;cas<=T;cas++){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<<<n;i++) sum[i]=,g[i]=,vis[i]=false;
for(int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
u[i]=x,v[i]=y;
g[<<x]|=<<y;
g[<<y]|=<<x;
}
for(int i=;i<<<n;i++) g[i]|=g[i-lb(i)]|g[lb(i)];
int l=,r=;
for(int i=;i<n;i++) vis[a[r++]=<<i]=true;
while(l<r){
int c=a[l++];
int res=g[c]^(g[c]&c);
while(res){
int tem=lb(res)|c;
if(!vis[tem]) vis[a[r++]=tem]=true;
res-=lb(res);
}
}
int all=;
for(int i=;i<<<n;i++){
int j=(<<n)-;
j^=i;
if(vis[i]&&vis[j]){
sum[i]++,sum[j]++,all++;
}
}
for(int j=;j<n;j++){
for(int i=(<<n)-;i>=;i--)
if(!(i&(<<j))) sum[i]+=sum[i^(<<j)];
}
printf("Case #%d: ",cas);
for(int i=;i<m;i++){
printf("%d",(all-sum[(<<u[i])|(<<v[i])])/);
if(i==m-) cout<<endl;
else cout<<" ";
}
}
return ; }
HDU5765 Bonds 最小割极的更多相关文章
- [洛谷]P3729 曼哈顿计划EX(最小割树/等价流树)
题目大意:给出一张n个点m条边的无向图,每个点有点权,q次询问,每次给出k,要求选出若干个点点权之和不小于k,求一个最大的值x,使得选出的点中任意两点之间至少有x条互不相交的链.(n<=550, ...
- bzoj 2039: [2009国家集训队]employ人员雇佣【最小割】
一开始在https://www.cnblogs.com/lokiii/p/10770919.html基础上连(i,j,b[i][j])建了个极丑的图T掉了--把dinic换成isap勉强能卡过 首先因 ...
- BZOJ 1391: [Ceoi2008]order [最小割]
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1509 Solved: 460[Submit][Statu ...
- BZOJ-2127-happiness(最小割)
2127: happiness(题解) Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1806 Solved: 875 Description 高一 ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- BZOJ3438 小M的作物(最小割)
题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=3438 Description 小M在MC里开辟了两块巨大的耕地A和B(你可以认为 ...
- 最大流-最小割 MAXFLOW-MINCUT ISAP
简单的叙述就不必了. 对于一个图,我们要找最大流,对于基于增广路径的算法,首先必须要建立反向边. 反向边的正确性: 我努力查找了许多资料,都没有找到理论上关于反向边正确性的证明. 但事实上,我们不难理 ...
- bzoj1412最小割
太羞耻了,m n写反了(主要是样例n m相等) 建图方法比较高(ji)端(chu),对于可以加栅栏的地方连上1的边,然后求最小割即可 为了让代码优(suo)美(duan),我写了一个check,避免多 ...
- 【BZOJ1497】[NOI2006]最大获利 最小割
裸的最小割,很经典的模型. 建图:要求总收益-总成本最大,那么将每条弧与源点相连,流量为成本,每个收益与汇点相连,流量为收益,然后每条弧与它所能到达的收益相连,流量为inf. 与源点相连的是未被选中的 ...
随机推荐
- 在对话框上拖动按钮并移动该按钮(改写CXXButton::PreTranslateMessage,然后MoveWindow)
// 派生自CButton类,主要过滤WM_LBUTTONDOWN .WM_LBUTTONUP和WM_MOUSEMOVE消息. BOOL m_bFlag = FALSE; // 成员变量,用来标示鼠标 ...
- [cocoapods]如何卸载cocoapods
今天我们来讲一下cocoapods的删除步骤! 1.移除pod组件,打开终端执行which pod 然后输出了路径,我的是 /usr/local/bin/pod 2. 移除Cocoapods组件,继续 ...
- NSArray 迭代
NSObject *obj=[[NSObject alloc]init]; NSArray *array=[[NSArray alloc] initWithObjects:@" ...
- Android ActionBar的Overlay模式如何不遮盖顶部内容的问题
关于actionbar的overlay模式请参考 如何让android的actionbar浮动且透明 一文.这篇文章讲的是如何在这种模式下让actionbar不遮住顶部的内容. 这 一般是这样的场景, ...
- MyEclipse 利用反向功能生成Java 实体类
1.Window -> Open Perspective -> MyEclipse Database Explorer 到DB Broswer界面 2.右键 -> New,新建一个数 ...
- Spring配置概述
1.Spring容器 1)要使应用程序中的Spring容器成功启动,需要以下三方面的条件都具备: · Spring架构的类包都已经放在应用程序的类路径下: · 应用程序为Spring提供完备的Bean ...
- POJ 水题若干
POJ 3176 Cow Bowling 链接: http://poj.org/problem?id=3176 这道题可以算是dp入门吧.可以用一个二维数组从下向上来搜索从而得到最大值. 优化之后可以 ...
- vmware shared holder 虚拟机设置共享目录
1, 安装 vm-tools http://askubuntu.com/questions/29284/how-do-i-mount-shared-folders-win7-host-in-ubunt ...
- BZOJ 2301 Problem b(莫比乌斯函数)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2301 题意:每次给出a,b,c,d,K.求有多少数对(x,y)满足a<=x< ...
- 1002: A+B for Input-Output Practice (II)
问题描述: http://acm.wust.edu.cn/problem.php?id=1002&soj=0 代码实现: import java.util.Scanner; public cl ...