It used to be two-figure matching, where the points in the same set were not interconnected.
But if you go to a general figure and ask for the maximum match of a general graph, use a flower tree to solve it.
With a flower tree template to handle the maximum match on an none graph
See for a while still don't understand copy of Kuangbin template familiar with a bit
There is also a general graph maximum weight match saved down VFK chicory template problem code as a board http://uoj.ac/submission/16359
I hope the next game will never be met. I can copy the right when I meet you. You can get through the wrong copy.
R ural1099
Kuangbin templates
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <map > #include <string> #include <vector> #include <queue> #include <iostream>using namespace std ; #define L long longint N; bool G[255][255];int match[255]; bool inque[255], inpath[255], inblo[255]; int head, tail; i NT que[255]; int St, fi; int newbase; int fa[255], base[255]; int cnt; void Creag () {int u, v; Memset (g, false, sizeof (g)); scanf ("%d", &n); while (scanf ("%d%d", &u, &v)!=eof) {G[u][v] = g[v][u] = true; }}void push (int u) {Que[tail] = u; Tail + +; Inque[u] = true;} int pop () {int res = Que[head]; Head + +; return res;} int FINDCA (int u, int v) {memset (Inpath, False, sizeof (Inpath)); while (true) {u = base[u]; Inpath[u] = true; if (U = = st) break; U = fa[match[u]]; } while (true) {v = base[v]; if (Inpath[v]) break; v = Fa[matCH[V]]; } return v;} void reset (int u) {int V; while (Base[u]! = newbase) {v = match[u]; Inblo[base[u]] = Inblo[base[v]] = true; U = fa[v]; if (base[u]! = newbase) Fa[u] = v; }}void Blocon (int u, int v) {newbase = FINDCA (u,v); Memset (Inblo, False, sizeof (Inblo)); Reset (U); Reset (v); if (base[u]! = newbase) Fa[u] = v; if (base[v]! = newbase) Fa[v] = u; for (int tu = 1; tu <= n; tu + +) {if (Inblo[base[tu]]) {Base[tu] = newbase; if (!inque[tu]) push (TU); }}}void FINDATP () {memset (Inque, False, sizeof (Inque)); memset (FA, 0, sizeof (FA)); for (int i = 1; I <= n; i + +) {Base[i] = i; } head = tail = 1; Push (ST); fi = 0; while (Head < tail) {int u = pop (); for (int v = 1; v <= N; v + +) {if (G[u][v] && (base[u]! = Base[v]) && (match[u]! = V)) { if (v = = st) | | ((MATCH[V) > 0) && fa[match[v]] > 0) {blocon (u,v); } else if (fa[v] = = 0) {Fa[v] = u; if (Match[v] > 0) {push (match[v]); } else {fi = v; break; }}}}}}void ap () {int u, V, W; U = fi; while (U > 0) {v = fa[u]; W = match[v]; MATCH[V] = u; Match[u] = v; u = w; }}void Edmonds () {memset (match, 0, sizeof (match)); for (int u = 1; u <= n; u + +) {if (match[u] = = 0) {st = u; FINDATP (); if (Fi > 0) {ap (); }}}}void print () {cnt = 0; for (int u = 1; u <= n; u + +) {if (Match[u] > 0) cnt + +; } printf ("%d\n", CNT); for (int u = 1; u <= n; u + +) {if (U &lT Match[u]) {printf ("%d%d\n", U, Match[u]); }}}int Main () {Creag (); Edmonds (); Print ();}
S hdu4687
Give a bunch of pair output the number of the pair that are not in any of the maximum matches
Not any of the maximum matching pair can only be its two endpoints have the required pair so this pair can not be substituted for the neighboring pair because if you replace the pair on the other end, you cannot choose
So enumerate each edge and remove the edges from the two ends of the edge. If two matches are lost, then this edge is not in any match.
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <map > #include <string> #include <vector> #include <queue> #include <iostream>using namespace std ; #define L long longint N, m; bool G[255][255];int match[255]; bool inque[255], inpath[255], inblo[255]; int head, Tai l; int que[255]; int St, fi; int newbase; int fa[255], base[255]; int cnt; int input[255][2]; int output[255]; bool Bf[2 55][255]; void Creag () {int u, v; Memset (g, false, sizeof (g)); Memset (BF, False, sizeof (BF)); for (int i = 1; I <= m; i + +) {scanf ("%d%d", &u,&v); G[U][V] = G[v][u] = true; BF[U][V] = Bf[v][u] = true; Input[i][0] = u; Input[i][1] = v; }}void push (int u) {Que[tail] = u; Tail + +; Inque[u] = true;} int pop () {int res = Que[head]; Head + +; return res;} int FINDCA (int u, int v) {memset (Inpath, False, sizeof (Inpath)); while (true) { U = base[u]; Inpath[u] = true; if (U = = st) break; U = fa[match[u]]; } while (true) {v = base[v]; if (Inpath[v]) break; v = fa[match[v]]; } return v;} void reset (int u) {int V; while (Base[u]! = newbase) {v = match[u]; Inblo[base[u]] = Inblo[base[v]] = true; U = fa[v]; if (base[u]! = newbase) Fa[u] = v; }}void Blocon (int u, int v) {newbase = FINDCA (u,v); Memset (Inblo, False, sizeof (Inblo)); Reset (U); Reset (v); if (base[u]! = newbase) Fa[u] = v; if (base[v]! = newbase) Fa[v] = u; for (int tu = 1; tu <= n; tu + +) {if (Inblo[base[tu]]) {Base[tu] = newbase; if (!inque[tu]) push (TU); }}}void FINDATP () {memset (Inque, False, sizeof (Inque)); memset (FA, 0, sizeof (FA)); for (int i = 1; I <= n; i + +) {Base[i] = i; } head = tail = 1; Push (ST); fi = 0; while (Head < tail) {int u = Pop (); for (int v = 1; v <= N; v + +) {if (G[u][v] && (base[u]! = Base[v]) && (match[u]! = V)) { if (v = = st) | | ((Match[v] > 0) && fa[match[v]] > 0) {Blocon (u,v); } else if (fa[v] = = 0) {Fa[v] = u; if (Match[v] > 0) {push (match[v]); } else {fi = v; break; }}}}}}void ap () {int u, V, W; U = fi; while (U > 0) {v = fa[u]; W = match[v]; MATCH[V] = u; Match[u] = v; u = w; }}void Edmonds () {memset (match, 0, sizeof (match)); for (int u = 1; u <= n; u + +) {if (match[u] = = 0) {st = u; FINDATP (); if (Fi > 0) {ap (); } } }}int print () {int cnt = 0; for (int u = 1; u <= n; u + +) {if (Match[u] > 0 && u < match[u]) {cnt + +; }} return cnt;} int main () {while (scanf ("%d%d", &n, &m)!=eof) {Creag (); Edmonds (); int res = print (); int ans = 0; for (int i = 1; I <= m; i + +) {int u = input[i][0]; int v = input[i][1]; for (int k = 1; k <= N; k + +) {for (int j = 1; J <= N; j + +) G[k][j] = Bf[k][j]; } for (int j = 1; J <= N; j + +) {G[j][v] = g[v][j] = g[u][j] = G[j][u] = false; } Edmonds (); int r = print (); if (r = = Res-2) {ans + +; Output[ans] = i; }} printf ("%d\n", ans); for (int i = 1; I <= ans; i + +) {printf ("%d", output[i]); if (i! = ans) printf (""); } printf ("\ n"); }}
The topic of the dichotomy is finally over.
I feel like I can only copy the template now.
Tomorrow... three of the best dishes from the Harbin Polytechnic. me and take me to fly my two teammates to go to ecfinal the problem of good luck ...
[Kuangbin take you to fly] topic ten matching problems general diagram matching