ps:sdoi2016 Round1 after Konjac Konjac began to do network flow to self-rescue (2016-04-11 in a few days to test first, now do network flow 24 seemingly nothing with ← retired rhythm)
The topic will be attached to the date, witness my turtle speed brush problem.
1. Pilot pairing Programme 2016-04-11
Binary graph maximum matching problem, updated the $dinic$ template, with the current ARC optimization and multi-channel augmentation. There are many kinds of output schemes for this problem, but there is no special judge, so there is no a, but the program number is correct. The legitimate output scheme can only be solved by the Hungarian algorithm.
#include <queue> #include <cstdio> #include <cstring> #include <algorithm> #define READ (x) x= Getint () using namespace std;const int N = 1003;int getint () {int k = 0, fh = 1; char c = GetChar (); for (; c < ' 0 ' | | C & Gt ' 9 '; c = GetChar ()) if (c = = '-') FH = -1;for (; c >= ' 0 ' && C <= ' 9 '; c = GetChar ()) K = k * + C-' 0 '; return k * FH;} Queue<int> q;bool vis[n];int Point[n], cap[n], nxt[n], to[n], d[n], cur[n], S, T, cnt = 1;bool BFS () {memset (Vis, 0, sizeof (VIS)); Q.push (S); D[s] = 0; Vis[s] = 1;int u, i;while (!q.empty ()) {u = Q.front (); Q.pop (); for (i = point[u]; i; i = Nxt[i]) if (!vis[to[i]] && Cap[i]) {D[to[i]] = D[u] + 1;vis[to[i]] = 1;q.push (To[i]);}} return vis[t];} int DFS (int u, int a) {if (U = = T | |!a) return a;int F, flow = 0;for (int i = cur[u]; i; i = Nxt[i]) if (D[u] + 1 = = D[to[i ] && (f = DFS (To[i], Min (A, cap[i]))) > 0) {flow + F; a-= f; cap[i] = f; cap[i ^ 1] + = f;if (!a) break; return flow;} int dinic () {int flow =0, I;while (BFS ()) {for (i = 1; I <= T; ++i) Cur[i] = Point[i];flow + = DFS (S, 0x7fffffff);} return flow;} void ins (int x, int y, int z) {nxt[++cnt] = point[x]; to[cnt] = y; cap[cnt] = Z; point[x] = cnt;} void Findpair (int x) {for (int i = point[x]; i; i = Nxt[i]) if (cap[i] = = 0 && to[i]! = S) {printf ("%d%d\n", X, to[ I]); Break;}} int main () {int n, m;read (n); read (m); S = n + M + 1; T = S + 1;for (int i = 1; I <= n; ++i) ins (s, I, 1), Ins (i, S, 0); for (int i = n + 1; I <= n + m; ++i) ins (i, T, 1), INS (T, I, 0); int u, V;read (U); Read (v), while (u! =-1 && v! =-1) {ins (U, V, 1), Ins (V, u, 0); Read (u); Read (v);} printf ("%d\n", Dinic ()), for (int i = 1; I <= n; ++i) Findpair (i); return 0;}
"Linear Programming and network flow 24 questions" completion (1/24)