# BZOJ1934【SHOI2007】善意的投票 <网络流>

3 3
1 0 0
1 2
1 3
3 2

1

2≤n≤300，1≤m≤n(n-1)/2。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define MAX_N 300
#define MAX_M MAX_N*(MAX_N-1)*2
#define INF 2147483647
using namespace std;
int n, m, s, t;
int d[MAX_N+5], first[MAX_N+5], cnt;
struct node {int v, c, next;} E[MAX_M+5];
void Init() {
cnt = 0;
memset(first, -1, sizeof(first));
}
void Insert(int u, int v, int c) {
E[cnt].v = v, E[cnt].c = c;
E[cnt].next = first[u];
first[u] = cnt++;
}
void AddEdge(int u, int v, int c) {
Insert(u, v, c);
Insert(v, u, 0);
}
bool BFS() {
memset(d, -1, sizeof(d));
queue <int> que;
que.push(s), d[s] = 0;
while (!que.empty()) {
int u = que.front();
for (int i = first[u]; i != -1; i = E[i].next) {
int v = E[i].v;
if (E[i].c && d[v] == -1) {
d[v] = d[u]+1;
que.push(v);
}
}
que.pop();
}
return (d[t] != -1);
}
int DFS(int u, int flow) {
if (u == t)	return flow;
int ret = 0;
for (int i = first[u]; i != -1; i = E[i].next) {
int v = E[i].v;
if (E[i].c && d[v] == d[u]+1) {
int tmp = DFS(v, min(flow, E[i].c));
if (!tmp)	continue;
flow -= tmp, E[i].c -= tmp;
ret += tmp, E[i^1].c += tmp;
if (!flow)	break;
}
}
if (!ret)	d[u] = -1;
return ret;
}
int Dinic() {
int ret = 0;
while (BFS())
ret += DFS(s, INF);
return ret;
}
int main() {
Init();	scanf("%d%d", &n, &m);
s = 0, t = n+1;
for (int i = 1; i <= n; i++) {
int f;	scanf("%d", &f);
if (f == 1) {
} else {