hdoj3251
这题告诉我们,最小割需:满流,S断不能到T端P4126,hdoj3987
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,SSZ=,APB=,one=;
const lon INF=0x7FFFFFFF,mod=;
int n,m,cnt,sum,head[SSZ],dep[SSZ],snum;
int S=,T=,nex[SZ],to[SZ],wt[SZ];
int vst[SSZ];
struct nd{
int x,y;
nd(int a=,int b=):x(a),y(b){}
};
nd arr[SZ]; void add(int u,int v,int w)
{
++cnt;
nex[cnt]=head[u];
head[u]=cnt;
to[cnt]=v,wt[cnt]=w;
} void init()
{
cnt=-,sum=;
memset(head,-,sizeof(head));
//cin>>n>>m>>snum;
scanf("%d%d%d",&n,&m,&snum);
for(int i=;i<=m;++i)
{
int a,b,c;
//cin>>a>>b>>c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,);
arr[i].x=a,arr[i].y=b;
}
for(int i=;i<=snum;++i)
{
int id,val;
cin>>id>>val;
add(id,T,val);
add(T,id,);
sum+=val;
}
add(S,,INF);
add(,S,);
} bool bfs()
{
memset(dep,,sizeof(dep));
dep[S]=;
queue<int> q;
q.push(S);
for(;q.size();)
{
int fr=q.front();
q.pop();
for(int i=head[fr];i!=-;i=nex[i])
{
int t=to[i],w=wt[i];
if(!dep[t]&&w)
{
dep[t]=dep[fr]+;
q.push(t);
if(t==T)return ;
}
}
}
return ;
} int dinic(int x,int flow)
{
if(x==T)return flow;
else
{
int rem=flow;
for(int i=head[x];i!=-&&rem;i=nex[i])
{
int t=to[i],w=wt[i];
if(dep[t]==dep[x]+&&w)
{
int tmp=dinic(t,min(rem,w));
if(!tmp)dep[t]=;
rem-=tmp;
wt[i]-=tmp,wt[i^]+=tmp;
}
}
return flow-rem;
}
} void dfs(int x,int p)
{
//cout<<x<<endl;
vst[x]=;
for(int i=head[x];i!=-;i=nex[i])
{
int t=to[i],w=wt[i];
if(t!=p&&w&&!vst[t])
{
dfs(t,x);
}
}
} void work()
{
int res=;
for(;bfs();)res+=dinic(S,INF);
cout<<sum-res<<endl;
dfs(S,-);
vector<int> tmp;
for(int i=;i<=m;++i)
{
//cout<<arr[i].x<<" "<<arr[i].y<<endl;
int u=arr[i].x,v=arr[i].y;
if(vst[u]&&!vst[v])
{
tmp.push_back(i);
}
}
cout<<tmp.size();
for(int i=;i<tmp.size();++i)
{
printf(" %d",tmp[i]);
}
cout<<endl;
} void release()
{
memset(vst,,sizeof(vst));
} int main()
{
//std::ios::sync_with_stdio(0);
//freopen("d:\\1.txt","r",stdin);
int casenum;
cin>>casenum;
//cout<<casenum<<endl;
for(int time=;time<=casenum;++time)
//for(int time=1;cin>>n>>m;++time)
{
printf("Case %d: ",time);
init();
work();
release();
}
return ;
}
hdoj3251的更多相关文章
随机推荐
- python安装setup.py问题
一:python下setuptools安装( No module named setuptools 解决方案) 1. 下载:在它的官网可以下载到安装包:https://pypi.python.org/ ...
- (转)Oracle EBS 有效银行账户取值 银行科目
SELECT ba.bank_account_id, --银行账户key ftv.territory_short_name, --国家 ftv.territory_code, --国家简称 cb.ba ...
- Replica Set + sharding搭建mongodb集群
先上几个用到的yaml文件,以后有时间了再更新,我是借鉴的https://blog.csdn.net/zeroctu/article/details/71082168,本人按照上面的搭建,是可行的,不 ...
- Git 工作环境配置
Git config 简单介绍 Git的配置选项有:-system,-global 和 -local. ① system:系统级别的全局设置,对所有电脑用户生效,文件在/etc/gitconfig: ...
- pgrep
优势:可以只显示进程号 pgrep -l 显示进程名
- 用iPhone查看pc电脑上写的html(Mac电脑Charles)简单版
对于客户端同学开发来说,写一段代码想在真机上看看,是非常容易的. 那么在这么一个大前端的环境下,客户端开发想写点html和js代码,又想在手机上看看效果,怎么办呢? 需要以下几个步骤: 大体流程:1. ...
- fastjson的简单使用
实习初期,开始接触到系统的后台日志查询展示到前台,后台将查询到的数据转化成json格式返回前台,发现系统使用的是阿里的fastjson,于是想来了解一下fastjson的使用. 以下使用都是基于这个版 ...
- iOS项目之使用开关控制日志输出的功能
最近一直在做sdk的项目,用户提出了一个需求,需要屏蔽sdk内部的日志输出.由于sdk内部的日志是为了调试,如果屏蔽了肯定不方便,所以研究了一下日志输出开关的功能. 在这里介绍两种实现方案:一种方案是 ...
- SQL 聚集函数(聚组函数)的使用 注意事项
原文地址 http://hi.baidu.com/sdunus/blog/item/333c1a29305041fe99250aad.html 在介绍GROUP BY 和 HAVING 子句前,我们必 ...
- appium+python3+pycharm踩得坑
错误: selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Ori ...