/**
[最大流] poj 1149 pigs
关键在于构图,
每个顾客分别用一个节点来表示。
对于每个猪圈的第一个顾客,从源点向他连一条边,容量就是该猪圈里的猪的初始数量。
如果从源点到一名顾客有多条边,则可以把它们合并成一条,容量相加。
对于每个猪圈,假设有 n 个顾客打开过它,
则对所有整数 i ∈ [1, n),从该猪圈的第 i 个顾客向第 i + 1 个顾客连一条边,容量为 +∞。
从各个顾客到汇点各有一条边,容量是各个顾客能买的数量上限。
last[i] 记录i个猪圈上次被谁打开
*/
#include <stdio.h>
#include <string.h>
#define typec int
#define N 100004
#define E 1100001
// type of cost
const typec inf = 1000000000;
// max of cost
struct edge { int x, y, nxt; typec c; } bf[E];
int ne, head[E], cur[E], ps[E], dep[E];
void addedge(int x, int y, typec c)
{
// add an arc(x -> y, c); vertex: 0 ~ n-1;
bf[ne].x = x; bf[ne].y = y; bf[ne].c = c;
bf[ne].nxt = head[x]; head[x] = ne++;
bf[ne].x = y; bf[ne].y = x; bf[ne].c = 0;
bf[ne].nxt = head[y]; head[