CTS2023琪露诺符卡交换是哪一种?

摘要:$text{Code}$ #include <bitsstdc++.h> using namespace std; template<
\(\text{Code}\) #include <bits/stdc++.h> using namespace std; template<typename Tp> void read(Tp &x) { x = 0; char ch = getchar(); int f = 0; for(; !isdigit(ch); f |= (ch == '-'), ch = getchar()); for(; isdigit(ch); x = (x<<3)+(x<<1)+(ch^48), ch = getchar()); } const int N = 205; int n, a[N][N], p[N][N], vis[N][N]; struct Network { const int inf = 300; int tot, h[N << 2], cur[N << 2], T, dep[N << 2]; struct edge{int to, nxt, w;}e[N * N << 2]; void init() { tot = 1, T = n + n + 1; for(int i = 0; i <= T; i++) h[i] = 0; } void add(int x, int y) { e[++tot] = edge{y, h[x], 1}, h[x] = tot; e[++tot] = edge{x, h[y], 0}, h[y] = tot; } queue<int> Q; int bfs() { for(int i = 0; i <= T; i++) dep[i] = 0, cur[i] = h[i]; Q.push(0), dep[0] = 1; while (!Q.empty()) { int now = Q.front(); Q.pop(); for(int i = h[now]; i; i = e[i].nxt) { int v = e[i].to; if (dep[v] || !e[i].w) continue; dep[v] = dep[now] + 1, Q.push(v); } } return dep[T]; } int dfs(int x, int lim) { if (lim <= 0 || x == T) return lim; int flow = 0; for(int i = cur[x], v, f; i; i = e[i].nxt) { cur[x] = i, v = e[i].to; if (dep[v] != dep[x] + 1 || !e[i].w) continue; f = dfs(v, min(lim, e[i].w)); if (f <= 0) continue; e[i].w -= f, e[i ^ 1].w += f, flow += f, lim -= f; if (lim <= 0) break; } return flow; } int dinic(){int flow = 0; while (bfs()) flow += dfs(0, inf); return flow;} void work(int t) { for(int i = 2; i <= tot; i++) if (!e[i].w && e[i ^ 1].to <= n) { if (!e[i].to || !e[i ^ 1].to) continue; int u = e[i ^ 1].to; for(int j = 1; j <= n; j+
阅读全文