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. Node基础:资源压缩之zlib

    概览 做过web性能优化的同学,对性能优化大杀器gzip应该不陌生.浏览器向服务器发起资源请求,比如下载一个js文件,服务器先对资源进行压缩,再返回给浏览器,以此节省流量,加快访问速度. 浏览器通过H ...

  2. Windows Azure 名词定义(Glossary)

    Glossary(名词) Definition(定义) Availability Set 可用性组 refers to two or more Virtual Machines deployed ac ...

  3. apply与call

    看这个apply真正应用.bind这是一个绑定时间的函数 var bind=function(object,type,fn){ if(object.attachEvent){//IE浏览器 objec ...

  4. Boostrap响应式与非响应式

    非响应式布局 在使用非响应式布局时,在<head>标签中需要加入一下内容,其中最主要的是non-responsive.css文件 <head> <meta http-eq ...

  5. AngularJS开发指南13:AngularJS的过滤器详解

    AngularJS过滤器是用来格式化输出数据的.除了格式化数据,过滤器还能修改DOM.这使得过滤器通常用来做些如“适时的给输出加入CSS样式”等工作. 比如,你可能有些数据在输出之前需要根据进行本地化 ...

  6. VS快速格式化代码

    Ctrl+E,D快速对所有文档进行格式化 Ctrl+E,F快速对选中内容进行格式化

  7. JS所谓的享元模式-->

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  8. 曲线行驶s弯道技巧图解【转】

    s弯道怎么走?在走S弯的时候,最主要的就是控制车的速度,在做每个动作的时候要保持一样的速度,不要一会快一会慢的,在开的时候,因为每个人的身高,体型不一样,每个人看的点位都是不一样的,每次在开的时候要找 ...

  9. Python 之我见

    读音 Python(KK 英语发音:/ˈpaɪθən/) 序言 其实早前就已经接触了python这个功能强大的脚本语言,但是那时只是基于兴趣而学习,目的性并不是很强,所以学习的并不是很深入.最近由于闲 ...

  10. str和repr的

    尽管str(),repr()和``运算在特性和功能方面都非常相似,事实上repr()和``做的是完全一样的事情,它们返回的是一个对象的“官方”字符串表示,也就是说绝大多数情况下可以通过求值运算(使用内 ...