【题目分析】

构造一个最小割的模型。

S向每一个点连Ai,每一个点向T连Bi。

对于每一个限制条件,在i和j之间连一条Cij的双向边即可。

然后求出最小割就是最少的花费。

验证最小割的合理性很容易。

【代码】

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> //#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 50005
#define ll long long
#define me 400005
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int h[me<<1],to[me<<1],ne[me<<1],fl[me<<1],en=0,S=0,T=me-1; void add(int a,int b,int c)
{
to[en]=b; ne[en]=h[a]; fl[en]=c; h[a]=en++;
// to[en]=a; ne[en]=h[b]; fl[en]=0; h[b]=en++;
} int map[me]; bool tell()
{
queue <int> q;
memset(map,-1,sizeof map);
map[S]=0;
while (!q.empty()) q.pop();
q.push(S);
while (!q.empty())
{
int x=q.front(); q.pop();
for (int i=h[x];i>=0;i=ne[i])
{
if (map[to[i]]==-1&&fl[i]>0)
{
map[to[i]]=map[x]+1;
q.push(to[i]);
}
}
}
if (map[T]!=-1) return true;
return false;
} int zeng(int k,int r)
{
if (k==T) return r;
int ret=0;
for (int i=h[k];i>=0&&ret<r;i=ne[i])
if (map[to[i]]==map[k]+1&&fl[i]>0)
{
int tmp=zeng(to[i],min(fl[i],r-ret));
ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp;
}
if (!ret) map[k]=-1;
return ret;
} int main()
{
memset(h,-1,sizeof h);
Finout();
int n,m,a,b,c;
n=Getint();m=Getint();
F(i,1,n)
{
a=Getint(); b=Getint();
add(S,i,a);
add(i,S,0);
add(i,T,b);
add(T,i,0);
}
F(i,1,m)
{
a=Getint(); b=Getint();
c=Getint();
add(a,b,c);
add(b,a,c);
}
int ans=0,tmp;
while (tell()) while (tmp=zeng(S,inf)) ans+=tmp;
cout<<ans<<endl;
}

  

POJ 3469 Dual Core CPU ——网络流的更多相关文章

  1. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  2. POJ 3469 Dual Core CPU Dual Core CPU

    Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 23780   Accepted: 10338 Case Time Lim ...

  3. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

  4. 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题

    [题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...

  5. poj 3469 Dual Core CPU——最小割

    题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...

  6. POJ 3469 Dual Core CPU(最小割)

    [题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...

  7. POJ 3469 Dual Core CPU (最小割建模)

    题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...

  8. poj 3469 Dual Core CPU

    题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...

  9. poj 3469 Dual Core CPU 最小割

    题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...

随机推荐

  1. Azure Powershell blob中指定的vhd创建虚拟机

    #此脚本用于 Azure 存储账户中已有 vhd 镜像文件创建虚拟机,一般用于做好镜像测试 #----------------------------------------------------- ...

  2. SQL Server中变量的声明和使用方法

    声明局部变量语法:DECLARE @variable_name DataType其中 variable_name为局部变量的名称,DataType为数据类型.给局部变量赋值有两种方法:1.SET @v ...

  3. hihoCode r#1077 : RMQ问题再临-线段树

    思路: 两种实现方法: (1)用链表(2)用数组. #include <bits/stdc++.h> using namespace std; int n, q, L, R, op, P, ...

  4. java日期操作的工具类时间格式的转换

    package cn.itcast.oa.util; import java.text.ParseException; import java.text.SimpleDateFormat;import ...

  5. Django 模型ORM

    from django.db import models # Create your models here. class Book(models.Model): nid = models.AutoF ...

  6. mysql安装(docker)

    mkdir /opt/mysql vim /opt/mysql/Dockerfile 5.7 FROM alpine FROM mysql:5.7.26 EXPOSE 3306 8.0 FROM al ...

  7. Jordan 标准型的推论

    将学习到什么 从 Jordan 标准型出发,能够获得非常有用的信息.   Jordan 矩阵的构造 Jordan 矩阵 \begin{align} J=\begin{bmatrix} J_{n_1}( ...

  8. 爬虫学习之pdf读取和存储

    在py3中如需进行pdf文件操作需要加载PDFMiner3K库文件,可通过pip方式或者可以下载源文件方式安装 python3 -m pip install pdfminer3k 下载源文件方式: 1 ...

  9. linux设置http/https proxy及忽略proxy的方法

    msys2设置网络代理 在文件 .bashrc 中添加 export http_proxy="proxy IP:port" 如 export http_proxy="19 ...

  10. 多线程threadvar 变量设定

    Delphi管理多线程之线程局部存储:threadvar 尽管多线程能够解决许多问题,但是同时它又给我们带来了很多的问题.其中主要的问题就是:对全局变量或句柄这样的全局资源如何访问?另外,当必须确保一 ...