After doing this for a long time, I finally found a problem that can only be done with Hungary .
One-eyed dichotomy, but the modeling is very ingenious. The idea at first was to take two attributes on either side of the dichotomy, but found that it seemed difficult to handle one of the cases.
In fact this should put the attribute on the left, the number is placed on the right to match on OK.
Because the number must be continuous for the sake of, dinic here is powerless,,, helpless to learn a bit Hungary,,,
#include <vector> #include <cstdio> #include <cstring> #include <cassert> #include <iostream > #include <algorithm>using namespace std;const int maxn = 1e6 + 10;inline int read () {char ch = getchar (); int x = 0; while (!isdigit (ch)) ch = GetChar (); while (IsDigit (ch)) x = x * + ch-' 0 ', ch = getchar (); return x;} int N; int MATCH[MAXN]; BOOL vis[maxn];vector<int> g[(int) 1e4 + 10];bool dfs (int u) {for (int i = 0; i < (int) g[u].size (); i++) { int &v = G[u][i]; if (!vis[v]) {Vis[v] = true; if (!match[v] | | DFS (MATCH[V)) return match[v] = u, true; }} return false;} int main () {cin>>n; for (int i = 1; I <= N; i++) G[read ()].push_back (i), G[read ()].push_back (i); int ans = 0; for (int i = 1; I <= (int) 1e4; i++) {memset (Vis, false, (N + 1) * sizeof (BOOL)); if (Dfs (i)) ++ans; else break; } printf ("%d\n", ans); return 0;}
P1640 [SCOI2010] continuous attack game