CSU 1249 竞争性酶抑制剂和同工酶
1249: 竞争性酶抑制剂和同工酶
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 109 Solved: 49
Description
Input
Output
每组测试数据输出一行。所需抑制剂的最小总量。
Sample Input
5 6
2 1 2
3 5 1
2 3 7
1 5 3
3 4 4
4 5 5
2 5
3 4
1 3 7
2 3 5
1 3 6
1 2 3
1 3
3 2
1 2 2
1 3 4
2 3
150 0
1 150
Sample Output
7
16
0
0
HINT
Source
解题:很明显最小割
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
};
arc e[maxn<<];
int head[maxn],d[maxn],cur[maxn];
int tot,S,T,n,m;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof(d));
d[T] = ;
q.push(T);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i^].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[S] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to]+==d[u]&&(a=dfs(e[i].to,min(e[i].flow,low)))){
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!tmp) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int ans = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
int main() {
int u,v,w;
while(~scanf("%d %d",&n,&m)){
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; ++i){
scanf("%d %d %d",&u,&v,&w);
add(u,v,w);
}
scanf("%d %d",&S,&T);
printf("%d\n",dinic());
}
return ;
}
CSU 1249 竞争性酶抑制剂和同工酶的更多相关文章
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
- CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...
- CSU 1120 病毒(DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...
- CSU 1116 Kingdoms(枚举最小生成树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
- CSU 1333 Funny Car Racing (最短路)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...
- CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...
- CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...
- hdu 1249 三角形
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1249 part=3*s*(s-1)+2 #include<stdio.h> #includ ...
随机推荐
- JS 判断中英文字符长度
function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { ...
- 【转载】Xmemcached用户指南
一.XMemcached简介 XMemcached是一个新java memcachedclient.也许你还不知道memcached是什么?可以先看看这里.简单来说,Memcached 是一个高性能的 ...
- iF.svnadmin 安装遇到的坑
iF.svnadmin 官网:http://svnadmin.insanefactory.com/ 安装配置iF.svnadmin : http://blog.linhere.com/archives ...
- 一个渣渣python脚本,用wol控制开机
#!/usr/bin/env python #coding:utf8 import os,time d={} '''f = open('E:\info.txt','r') for ipmac in f ...
- js Date() 时间函数处理 关于 toLocaleDateString()
toLocaleDateString()方法的真正含义为「根据本地时间把Date对象的日期部分转换为字符串」,这意味着:在不同的浏览器或者服务器中,我们可能得到不同的字符串. 例如,将 Chrome ...
- 阿里云部署java项目
第一步:注册阿里云账号(如果有请看第二步) 1.百度搜索阿里云,点击进入阿里云官网 2.点击右上角免费注册 3.进入注册页面,按照要求填写信息 4.注册完成后登陆 登陆之后首先购买阿里云esc与服务器 ...
- SPOJ 962 Intergalactic Map
Intergalactic Map Time Limit: 6000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Ori ...
- C++容器(二):关联容器简介
关联容器(associative container)与顺序容器的本质区别在于:关联容器通过键(Key)存储和读取元素,而顺序容器则通过元素在容器中的位置顺序存储和访问元素.虽然,关联容器的大部分行为 ...
- The Karplus-Strong Algorithm
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/48730857 Karplus-Stro ...
- 洛谷 P3662 [USACO17FEB]Why Did the Cow Cross the Road II S
P3662 [USACO17FEB]Why Did the Cow Cross the Road II S 题目描述 The long road through Farmer John's farm ...