水题笔记_ [JLOI2010]冠军调查 [网络流, 最小割]

一中药丸了…

希望学弟学妹们还是要振作起来啊…

懵逼的 题目

扯淡的 题解

很简单很套路的题…一个点割到那一边都会对应一个割大小的[违心 + 伤心]人数, 所以最小割就行了
$$
S \to i \,\,\, win(i) = 1\\
i \to T \,\,\, win(i) = 0\\
i \to j,\, j \to i \,\,\, friends(i, j) = true
$$

沙茶的 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**************************************************************
Problem: 2768
User: Cansult
Language: C++
Result: Accepted
Time:184 ms
Memory:21604 kb
****************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define MAXN (100000 + 5)
#define MAXM (500000 + 5)
#define INF (0X7FFFFFFF)
#define rev(i) ((i) ^ 1)
const int s = 0, t = MAXN - 1;
using namespace std;
struct edg
{
int from, to, next, cap, flow;
edg() {}
edg(int fr, int dqt, int ne, int ca): from(fr), to(dqt), next(ne), cap(ca), flow(0) {}
}b[MAXM << 1];
int g[MAXN], cntb = -1, dis[MAXN], ans, n, m;
void adn(int from, int to, int cap)
{
b[++cntb] = edg(from, to, g[from], cap);
g[from] = cntb;
}
int dinic(int dq, int maxf)
{
if (dq == t || !maxf)
return maxf;
int re = 0;
for (int i = g[dq]; ~i; i = b[i].next)
if (b[i].cap > b[i].flow && dis[b[i].to] == dis[dq] + 1)
{
int zl = dinic(b[i].to, min(b[i].cap - b[i].flow, maxf));
maxf -= zl;
re += zl;
b[i].flow += zl;
b[rev(i)].flow -= zl;
}
return re;
}
bool bfs()
{
queue<int> q;
memset(dis, 0, sizeof(dis));
dis[s] = 1;
q.push(s);
while (!q.empty())
{
int dq = q.front();
q.pop();
for (int i = g[dq]; ~i; i = b[i].next)
if (b[i].cap > b[i].flow && !dis[b[i].to])
dis[b[i].to] = dis[dq] + 1, q.push(b[i].to);
}
return dis[t] > 0;
}
void solve()
{
while (bfs())
ans += dinic(s, INF);
}
int main()
{
// cout << "Hello world!" << endl;
memset(g, -1, sizeof(g));
scanf("%d%d", &n, &m);
for (int i = 1, srx; i <= n; i++)
{
scanf("%d", &srx);
if (srx)
adn(s, i, 1), adn(i, s, 0);
else
adn(i, t, 1), adn(t, i, 0);
}
for (int i = 1, srx, sry; i <= m; i++)
{
scanf("%d%d", &srx, &sry);
adn(srx, sry, 1);
adn(sry, srx, 0);
adn(sry, srx, 1);
adn(srx, sry, 0);
}
solve();
printf("%d", ans);
return 0;
}

By 遗民 Cansult