这题告诉我们,最小割需:满流,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的更多相关文章

随机推荐

  1. python-爬虫(3)---lxml匹配css

    百度首页  部分代码 <div class="s_tab_inner"> <b>网页</b> <a href="//www.ba ...

  2. 蓝桥杯近3年决赛题之3(17年b组)

    做的时候对了2个小题,一个大题可能会拿点分数. 1. 标题:36进制 对于16进制,我们使用字母A-F来表示10及以上的数字.如法炮制,一直用到字母Z,就可以表示36进制. 36进制中,A表示10,Z ...

  3. Jenkins官方社区携手灵雀云成功举办Jenkins Meetup

    10月27日,由 Jenkins 官方社区和灵雀云主办的 Jenkins 插件开发 Meetup 在北京中科曙光大厦成功举办.这是Hacktoberfest(即 Hack October Festiv ...

  4. C博客作业05--指针

    1. 本章学习总结 1.1 思维导图 1.2 本章学习体会及代码量学习体会 1.2.1 学习体会 这几周学习了指针,指针是C语言的一个重要的概念,也是特色之一.它可以通过对地址的访问来改变值,所以它的 ...

  5. [dart学习]第一篇:windows下安装配置dart编译环境,写出helloworld

    前言 博主非科班出身,平时多用C语言,最近想了解学习一门第二语言,看上了可用于移动开发的目前还小众一点dart,准备用一段比较长的时间来慢慢学习.理解. 关于dart语言不再详细介绍了,大家可以访问  ...

  6. IDEA日常遇到问题汇总

    1. IDEA .gitignore文件不显示在项目栏中 解决方法,setting  >> Editor >> Code Style >> File Type &g ...

  7. 安卓入门——————简单记账本的开发(用sqlite存储数据)(一)

    设计思想————首先要确定有几个页面.和每个页面的大致布局 由于是入门,我也是学习了不是很长的时间,所以项目比较low.... 第一个页面,也就是打开APP的首页面: 今天这个博客,先实现添加功能!: ...

  8. what i want

    i want to be the object of every beautiful creature. they strongly want to talk with me, and study f ...

  9. 微服务化的大坑之一:当dubbo神器碰上共用注册中心和错误的暴露接口

    dubbo是国内用比较多的微服务化系统,非侵入(意思就是说不用自己写代码,把xml配置好就可以用了,这个xml的引用注解就注在springboot的开启main类里面就可以了),提供好用的均衡和容错机 ...

  10. 记华硕小主机装xp并给nokia e7-00 刷机

    前言 事情是这样的,年前给早先收的小e买了触摸外屏.这会儿有空就给它换上了屏幕,然后尝试装app的时候,发现证书有问题. 根据以往使用n73的经验,然后就百度怎么破解证书. 然后我发现,这些东西网上资 ...