# BZOJ1934: [Shoi2007]Vote 善意的投票

## 1934: [Shoi2007]Vote 善意的投票

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 2489  Solved: 1544
[Submit][Status][Discuss]

3 3
1 0 0
1 2
1 3
3 2

1

## Source

【题解】

S连向同意的点，我们把这些边记做s边，由S连出的点叫s点

  1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cstdlib>
5 #include <algorithm>
6 #include <cmath>
7 #include <queue>
8 #include <vector>
9 #define min(a, b) ((a) < (b) ? (a) : (b))
10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
12 inline void swap(int &a, int &b)
13 {
14     long long tmp = a;a = b;b = tmp;
15 }
17 {
18     x = 0;char ch = getchar(), c = ch;
19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
21     if(c == '-')x = -x;
22 }
23
24 const int INF = 0x3f3f3f3f;
25 const int MAXN = 500;
26 const int MAXM = 1000000;
27
28 struct Edge
29 {
30     int u,v,w,nxt;
31     Edge(int _u, int _v, int _w, int _nxt){u = _u;v = _v;w = _w;nxt = _nxt;}
32     Edge(){}
33 }edge[MAXM << 1];
34 int head[MAXN], cnt = 1, q[MAXN], h[MAXN], ans = 0, S, T;
35
36 inline void insert(int a, int b, int c)
37 {
42 }
43
44 bool bfs()
45 {
46     int he = 0, ta = 1;
47     memset(h, -1, sizeof(h));
48     q[he] = S, h[S] = 0;
49     while(he < ta)
50     {
51         int now = q[he ++];
52         for(int pos = head[now];pos;pos = edge[pos].nxt)
53         {
54             int v = edge[pos].v;
55             if(h[v] == -1 && edge[pos].w)
56             {
57                 h[v] = h[now] + 1;
58                 q[ta ++] = v;
59             }
60         }
61     }
62     return h[T] != -1;
63 }
64
65 int dfs(int x, int f)
66 {
67     if(x == T) return f;
68     int w, used = 0;
69     for(int pos = head[x];pos;pos = edge[pos].nxt)
70     {
71         int v = edge[pos].v;
72         if(h[v] == h[x] + 1)
73         {
74             w = dfs(v, min(f - used, edge[pos].w));
75             edge[pos].w -= w;
76             edge[pos ^ 1].w += w;
77             used += w;
78             if(used == f) return f;
79         }
80     }
81     if(!used) h[x] = -1;
82     return used;
83 }
84
85 void dinic()
86 {
87     while(bfs()) ans += dfs(S, INF);
88 }
89
90 int n,m;
91
92 int main()
93 {
94     S = 301, T = 302;
96     for(register int i = 1;i <= n;++ i)
97     {
99         if(tmp) insert(S, i, 1);
100         else insert(i, T, 1);
101     }
102     for(register int i = 1;i <= m;++ i)
103     {
104         int tmp1,tmp2;
112 }