ACM Computer Factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5596   Accepted: 1922   Special Judge

Description

As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.

Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn't matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.

The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.

After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.

As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.

Input

Input file contains integers P N, then N descriptions of the machines. The description of ith machine is represented as by 2 P + 1 integers Qi Si,1 Si,2...Si,P Di,1 Di,2...Di,P, where Qi specifies performance, Si,j— input specification for part jDi,k — output specification for part k.

Constraints

1 ≤ P ≤ 10, 1 ≤ ≤ 50, 1 ≤ Qi ≤ 10000

Output

Output the maximum possible overall performance, then M — number of connections that must be made, then M descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, where W is the number of computers delivered from A to B per hour.

If several solutions exist, output any of them.

Sample Input

Sample input 1
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1
Sample input 2
3 5
5 0 0 0 0 1 0
100 0 1 0 1 0 1
3 0 1 0 1 1 0
1 1 0 1 1 1 0
300 1 1 2 1 1 1
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1

Sample Output

Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.

Source

Northeastern Europe 2005, Far-Eastern Subregion
跟poj1459差不多,就是net要自己连上线
dinic 0ms 
 #include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
const int M = , inf = 0x3f3f3f3f ;
struct edge
{
int u , v , timeu ;
int w ;
}e[M * M * ]; struct node
{
int input[] , output[] ;
int w ;
}o[M]; int p , n ;
int src , des ;
int dis[M] ;
int head[M * M * ] ;
int cnt , app ;
struct ABW
{
int a , b , w ;
}step[M * M * ]; bool bfs ()
{
queue <int> q ;
while (!q.empty ())
q.pop () ;
memset (dis , - , sizeof(dis)) ;
dis[src] = ;
q.push (src) ;
while (!q.empty ()) {
int u = q.front () ;
q.pop () ;
for (int i = head[u] ; i != - ; i = e[i].timeu) {
int v = e[i].v ;
if (dis[v] == - && e[i].w > ) {
dis[v] = dis[u] + ;
q.push (v) ;
}
}
}
if (dis[des] > )
return true ;
return false ;
} int dfs (int u , int low)
{
int a = ;
if (u == des)
return low ;
for (int i = head[u] ; i != - ; i = e[i].timeu) {
int v = e[i].v ;
if (e[i].w > && dis[v] == dis[u] + && (a = dfs (v , min (low , e[i].w)))) {
e[i].w -= a ;
if (e[i].u != src && e[i].v != des) {
step[app].a = e[i].u ; step[app].b = e[i].v ; step[app].w = a ;
app++ ;
}
e[i^].w += a ;
return a ;
}
}
dis[u] = - ;
return ;
} void dinic ()
{
int ans = , res = ;
app = ;
while (bfs ()) {
while () {
if (ans = dfs (src , inf))
res += ans ;
else
break ;
}
}
printf ("%d %d\n" , res , app) ;
for (int i = app - ; i >= ; i--)
printf ("%d %d %d\n" , step[i].a + , step[i].b + , step[i].w) ;
} void addedge (int u , int v)
{
e[cnt].u = u ; e[cnt].v = v ; e[cnt].w = o[u].w == - ? o[v].w : o[u].w ; e[cnt].timeu = head[u] ;
head[u] = cnt++ ;
e[cnt].u = v ; e[cnt].v = u ; e[cnt].w = ; e[cnt].timeu = head[v] ;
head[v] = cnt++ ;
} void binary (int s , int l , int r)
{
if (l == r) {
if (s != l && l != n) {
int i ;
for (i = ; i < p ; i++) {
if (o[l].input[i] != && o[s].output[i] != o[l].input[i])
break ;
}
if (i == p) {
addedge (s , l) ;
}
}
return ;
}
int mid = l + r >> ;
binary (s , l , mid) ;
binary (s , mid + , r) ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
while (~ scanf ("%d%d" , &p , &n)) {
for (int i = ; i < n ; i++) {
scanf ("%d" , &o[i].w) ;
for (int j = ; j < p ; j++) {
scanf ("%d" , &o[i].input[j]) ;
}
for (int j = ; j < p ; j++) {
scanf ("%d" , &o[i].output[j]) ;
}
}
for (int i = ; i < p ; i++) {
o[n].input[i] = o[n].output[i] = ;//源点
o[n + ].input[i] = o[n + ].output[i] = ;//汇点
}
o[n].w = - , o[n + ].w = - ;
src = n , des = n + ; n += ;
cnt = ;
memset (head , - , sizeof(head)) ;
for (int i = ; i < n - ; i++) {
binary(i , , n) ;
}
/* for (int i = 0 ; i < cnt ; i++) {
if (i % 2 == 0)
printf ("%d-->%d === %d , time: %d\n" , e[i].u , e[i].v , e[i].w , e[i].timeu) ;
}
puts ("") ; */
dinic () ;
}
return ;
}

ACM Computer Factory(dinic)的更多相关文章

  1. POJ-3436:ACM Computer Factory (Dinic最大流)

    题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...

  2. POJ 3436 ACM Computer Factory (网络流,最大流)

    POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...

  3. POJ3436 ACM Computer Factory(最大流/Dinic)题解

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8944   Accepted: 3 ...

  4. POJ3436:ACM Computer Factory(最大流)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9963   Accepted: 3 ...

  5. POJ-3436 ACM Computer Factory(网络流EK)

    As you know, all the computers used for ACM contests must be identical, so the participants compete ...

  6. POJ - 3436 ACM Computer Factory(最大流)

    https://vjudge.net/problem/POJ-3436 题目描述:  正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...

  7. POJ 3436 ACM Computer Factory(最大流+路径输出)

    http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...

  8. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

  9. ACM Computer Factory - poj 3436 (最大流)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5949   Accepted: 2053   Special Judge ...

随机推荐

  1. WPF Command Binding

    <Window x:Class="WpfTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...

  2. 原生JS、CSS实现的转盘效果(目前仅支持webkit)

    这是一个原生JS.CSS实现的转盘效果(题目在这:http://www.cnblogs.com/arfeizhang/p/turntable.html),花了半个小时左右,准备睡觉,所以先贴一段代码, ...

  3. 用javascript实现简单排序算法

    声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 本文为楼主自己的学习记录文章,若有不当之处请斧正. 本文主要记录排序算法 [冒泡排序] 感觉这个是最简单的排序算法了.直接引用维基百科里的 ...

  4. 判断一个点是否在多边形内部,射线法思路,C#实现

    感谢原作者,原理请看原作者的文章 http://www.html-js.com/article/1517 C#实现 public string rayCasting(PointF p, PointF[ ...

  5. [设计模式] javascript 之 代理模式

    代理模式说明 说明:顾名思义就是用一个类来代替另一个类来执行方法功能,这个模式跟装饰模式有点相似,不一样的是,代理模式是代替客户初始化被代理对象类,而装饰模式采用接口或初装饰者参数引用的方式来执行的. ...

  6. WCF安装Windows服务

    安装图解: 安装命令: 1. 开始 ->运行 ->cmd2. cd到C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319(Framework版本号按I ...

  7. iOS--隐藏和显示TabBar的方法

    1.隐藏TabBar: - (void)hideTabBar { if (self.tabBarController.tabBar.hidden == YES) { return; } UIView  ...

  8. requirejs

    //index.html <!doctype html> <html> <head> <meta charset="utf-8"> ...

  9. 统计"1"个数问题

    问题: 给定一个十进制整数N,求出从1到N的所有整数中出现”1”的个数. 例如:N=2时 1,2出现了1个 “1” . N=12时 1,2,3,4,5,6,7,8,9,10,11,12.出现了5个“1 ...

  10. Angulajs系列-01-入门

    1.解决什么问题? a, controller的各种的创建 b,体验angular的双向绑定 2.怎么解决 2.1 引入angularjs 下载地址 2.2 创建controller的方法 2.2.1 ...