AC日记——Destroying The Graph poj 2125
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 8356 | Accepted: 2696 | Special Judge |
Description
Alice assigns two costs to each vertex: Wi+ and Wi-. If Bob removes all arcs incoming into the i-th vertex he pays Wi+ dollars to Alice, and if he removes outgoing arcs he pays Wi- dollars.
Find out what minimal sum Bob needs to remove all arcs from the graph.
Input
Output
Sample Input
3 6
1 2 3
4 2 1
1 2
1 1
3 2
1 2
3 1
2 3
Sample Output
5
3
1 +
2 -
2 +
Source
思路:
最小点权覆盖;
来,上代码:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream> #define INF 0x7ffffff using namespace std; struct EdgeType {
int v,e,f;
};
struct EdgeType edge[<<]; int n,m,vout[],vin[],s,t;
int head[],deep[],cnt=,ans; bool if_[]; char Cget; inline void in(int &now)
{
now=,Cget=getchar();
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(int u,int v,int f)
{
edge[++cnt].v=v,edge[cnt].f=f,edge[cnt].e=head[u],head[u]=cnt;
edge[++cnt].v=u,edge[cnt].f=,edge[cnt].e=head[v],head[v]=cnt;
} bool BFS()
{
for(int i=s;i<=t;i++) deep[i]=-;
queue<int>que;que.push(s);deep[s]=;
while(!que.empty())
{
int now=que.front();
for(int i=head[now];i;i=edge[i].e)
{
if(deep[edge[i].v]<&&edge[i].f>)
{
deep[edge[i].v]=deep[now]+;
if(edge[i].v==t) return true;
que.push(edge[i].v);
}
}
que.pop();
}
return false;
} int flowing(int now,int flow)
{
if(now==t||flow==) return flow;
int oldflow=;
for(int i=head[now];i;i=edge[i].e)
{
if(deep[edge[i].v]!=deep[now]+||edge[i].f==) continue;
int pos=flowing(edge[i].v,min(flow,edge[i].f));
flow-=pos;
oldflow+=pos;
edge[i].f-=pos;
edge[i^].f+=pos;
if(flow==) return oldflow;
}
if(oldflow==) deep[now]=-;
return oldflow;
} void check(int now)
{
if_[now]=true;
for(int i=head[now];i;i=edge[i].e)
{
if(!edge[i].f||if_[edge[i].v]) continue;
check(edge[i].v);
}
} int main()
{
in(n),in(m);
s=,t=n+n+;
for(int i=;i<=n;i++)
{
in(vout[i]);
edge_add(i+n,t,vout[i]);
}
for(int i=;i<=n;i++)
{
in(vin[i]);
edge_add(s,i,vin[i]);
}
int u,v;
for(int i=;i<=m;i++)
{
in(u),in(v);
edge_add(u,v+n,INF);
}
while(BFS()) ans+=flowing(s,INF);
cout<<ans;ans=;
putchar('\n');check(s);
for(int i=;i<=n;i++)
{
if(!if_[i]) ans++;
if(if_[i+n]) ans++;
}
cout<<ans;putchar('\n');
for(int i=;i<=n;i++)
{
if(!if_[i]) printf("%d -\n",i);
if(if_[i+n]) printf("%d +\n",i);
}
return ;
}
AC日记——Destroying The Graph poj 2125的更多相关文章
- AC日记——青蛙的约会 poj 1061
青蛙的约会 POJ - 1061 思路: 扩展欧几里得: 设青蛙们要跳k步,我们可以得出式子 m*k+a≡n*k+b(mod l) 式子变形得到 m*k+a-n*k-b=t*l (m-n)*k-t ...
- poj 2125 Destroying The Graph (最小点权覆盖)
Destroying The Graph http://poj.org/problem?id=2125 Time Limit: 2000MS Memory Limit: 65536K ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- 【POJ】【2125】Destroying the Graph
网络流/二分图最小点权覆盖 果然还是应该先看下胡伯涛的论文…… orz proverbs 题意: N个点M条边的有向图,给出如下两种操作.删除点i的所有出边,代价是Ai.删除点j的所有入边,代价是Bj ...
- 图论(网络流,二分图最小点权覆盖):POJ 2125 Destroying The Graph
Destroying The Graph Description Alice and Bob play the following game. First, Alice draws some di ...
- POJ 2125 Destroying The Graph [最小割 打印方案]
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8311 Accepted: 2 ...
- POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)
Destroying The Graph Time Limit: 2000MS Memo ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- Destroying The Graph 最小点权集--最小割--最大流
Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...
随机推荐
- composer安装laravel-u-editor及其使用
前言 使用的框架是laravel5.1,是composer搭建的,可以直接配置composer,如果不是composer搭建的larave,需要先安装composer,具体安装发放可以参考compo ...
- 11Vim文本编辑器
Vim文本编辑器 在Linux系统中一切都是文件,而配置一个服务就是在修改其配置文件的参数. Vim提供了三种模式:命令模式.输入模式.末行模式 1.命令模式 每次运行Vim编辑器时,默认进入命令模式 ...
- ipvsadm分发MySQL读请求
在MySQL的部署场景中,经常使用HAproxy和ipvs来作为读请求转发的网关.ipvs的好处在于本身不需要daemon的方式来运行,而是直接作为kernel的服务来提供:当ipvs和应用程序服务器 ...
- thinkphp5开发restful-api接口学习 教程视频 接口文档
目录 1. 获取验证码 2. 用户注册 3. 用户登录 4. 用户上传头像 5. 用户修改密码 6. 用户找回密码 7. 用户绑定手机号 8. 用户绑定邮箱 9. 用户绑定用户名(手机/邮箱) 10. ...
- Decorator——Python初级函数装饰器
最近想整一整数据分析,在看一本关于数据分析的书中提到了(1)if __name__ == '__main__' (2)列表解析式 (3)装饰器. 先简单描述一下前两点,再详细解说Python初级的函数 ...
- 中移物联网onenet入门学习笔记1:资料获取
onenet学习资料.视频.例程汇总:https://open.iot.10086.cn/bbs/thread-977-1-1.html onenet开发文档:https://open.iot.100 ...
- LeetCode(128) Longest Consecutive Sequence
题目 Given an unsorted array of integers, find the length of the longest consecutive elements sequence ...
- 水题:UVa213- Message Decoding
Message Decoding Some message encoding schemes require that an encoded message be sent in two parts. ...
- 利用virt-manager,xmanager, xshell启动界面来管理虚拟机
有时候我们需要搭建一套自己的简单环境来启动一个虚拟机,验证一些问题. 1.首先我利用vmware workstation来创建centos7虚拟机,然后开启虚拟化,如下图所示. 2.其次,启动虚拟机, ...
- jenkins匿名用户登录 - 安全设置
最近自己安装配置jenkins,但是跑任务时,发现是匿名账户登录,且提示: 后来发现搭建好jenkins之后,默认就是匿名用户登录的,可以在安装设置菜单里进行账户管理. 1.登录Jenkins服务器, ...