#include using namespace std; using int64 = long long; /* * @title Zarts - 座標圧縮 * @docs md/util/Zarts.md */ template class Zarts{ vector value; map key; size_t sz; public: vector compressed; Zarts(const vector & ar, int light_flag = 0, T pre=-1) : compressed(ar.size()) { if(!light_flag) { for (auto &e : ar) key[e]; int cnt=0; for (auto &e : key) e.second = cnt++; for (int i=0;i> ord(ar.size()); for(int i=0;i class Dinic { struct info { int to, rev; T cap; }; T ini, inf; vector> edge; vector level, iter; inline void bfs(int start) { for (int i = 0; i < level.size(); ++i) level[i] = -1; queue q; level[start] = 0; q.push(start); while (q.size()) { int from = q.front(); q.pop(); for (auto& e : edge[from]) { if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[from] + 1; q.push(e.to); } } } } inline T dfs(int from, int goal, T flow) { if (from == goal) return flow; for (int& i = iter[from]; i < edge[from].size(); ++i) { auto& e = edge[from][i]; if (e.cap <= 0 || level[from] >= level[e.to]) continue; T dflow = dfs(e.to, goal, min(flow, e.cap)); if (dflow <= 0) continue; e.cap -= dflow; edge[e.to][e.rev].cap += dflow; return dflow; } return ini; } public: Dinic(int N, T ini, T inf) : edge(N), level(N), iter(N), ini(ini), inf(inf) { // do nothing } inline void make_edge(int from, int to, T cap) { edge[from].push_back({ to, (int)edge[to].size(), cap }); edge[to].push_back({ from, (int)edge[from].size() - 1, ini }); } inline T maxflow(int start, int goal) { T maxflow = ini; while (1) { bfs(start); if (level[goal] < 0) return maxflow; for (int i = 0; i < iter.size(); ++i) iter[i] = 0; T flow; while ((flow = dfs(start, goal, inf))>0) maxflow += flow; } } }; //verify https://atcoder.jp/contests/arc085/tasks/arc085_c int solve(int H, vector A, int W, vector B) { int N = A.size(); int inf = 1000000; //行: 「操作を行う」:0,「操作を行わない」:1と割り当てる //列: 「操作を行わない」:0,「操作を行う」:1と割り当てる Dinic di(H+W+2,0,inf); int S = H+W, G = H+W+1; int ans = 0; //iが0なら1失う for(int i=0;i> H >> W; int M = 500010; vector>> vvp(M); for(int i=0;i> a; vvp[a].push_back({i,j}); } } int ans = 0; for(int i=1;i Y(n),X(n); for(int j=0;j ZY(Y),ZX(X); int cnt = solve(ZY.size(),ZY.compressed,ZX.size(),ZX.compressed); ans += abs(cnt); } cout << ans << endl; return 0; }