正文
增加 10 行删除 10 行
1234567891011121399 行未改动1131141151161171181191201218 行未改动13013113213313413513613713813914014114214314414514614749 行未改动19719819920020120220320420520620720820921021121221321421521621721821922014 行未改动**题目链接**[atcoder](https://atcoder.jp/contests/agc038/tasks/agc038_f)[luogu](https://www.luogu.com.cn/problem/AT_agc038_f)# 题目简介给定 $P, Q$ 两个排列,目标求 $A, B$ 两个排列满足$A_i \in \{i, P_i\}$, $B_i \in \{i, Q_i\}$ **最大化** $A_i \neq B_i$ 的数量。数据范围:$n \leq 10^5$99 行未改动struct edge {int to, cap, rev;//to 代表要去到的点//cap 代表流量上限(最大流中用到,其实就是选择代价)//rev 是在 to 的邻接表中起点的下标,便于回溯};int depth[maxn], iter[maxn], s, t, mxnodes, n;//depth 是在当前bfs的深度,iter为当前弧优化数组,非常重要8 行未改动}bool bfs() {//bfs计算深度以及连通性for(int i = 0; i <= mxnodes; i++) depth[i] = -1;depth[s] = 0;queue<int> q; q.push(s);while(!q.empty()) {int u = q.front(); q.pop();for(auto &e : adj[u]) {if(e.cap > 0 && depth[e.to] == -1) {depth[e.to] = depth[u] + 1;q.push(e.to);} } }return depth[t] != -1;}int dfs(int v, int flow) {//dfs计算阻塞流if(v == t) return flow;49 行未改动cin >> n;p.resize(n); q.resize(n);for(int i = 0; i < n; i++) cin >> p[i];for(int i = 0; i < n; i++) cin >> q[i];int pcyc = 0, qcyc = 0;vector<int> pid = getcyc(p, pcyc);vector<int> qid = getcyc(q, qcyc);s = 0, t = 1;int pbase = 2, qbase = 2 + pcyc;mxnodes = qbase + qcyc;int base = 0;for(int i = 0; i < n; i++) {bool pisfixed = (p[i] == i);bool qisfixed = (q[i] == i);int u = pbase + pid[i];int v = qbase + qid[i];if(pisfixed && qisfixed) {//情况在上面都有解释base++;} else if(pisfixed && !qisfixed) {addedge(s, v, 1);14 行未改动1234567891011121399 行未改动1131141151161171181191201218 行未改动13013113213313413513613713813914014114214314414514614749 行未改动19719819920020120220320420520620720820921021121221321421521621721821922014 行未改动**题目链接**[atcoder](https://atcoder.jp/contests/agc038/tasks/agc038_f)[luogu](https://www.luogu.com.cn/problem/AT_agc038_f)# 题目简介给定 $P, Q$ 两个排列,目标求 $A, B$ 两个排列满足$A_i \in \{i, P_i\}$, $B_i \in \{i, Q_i\}$ **最大化** $A_i \neq B_i$ 的数量。数据范围:$n \leq 10^5$99 行未改动struct edge {int to, cap, rev;//to 代表要去到的点//cap 代表流量上限(最大流中用到,其实就是选择代价)//rev 是在 to 的邻接表中起点的下标,便于回溯};int depth[maxn], iter[maxn], s, t, mxnodes, n;//depth 是在当前bfs的深度,iter为当前弧优化数组,非常重要8 行未改动}bool bfs() {//bfs计算深度以及连通性for(int i = 0; i <= mxnodes; i++) depth[i] = -1;depth[s] = 0;queue<int> q; q.push(s);while(!q.empty()) {int u = q.front(); q.pop();for(auto &e : adj[u]) {if(e.cap > 0 && depth[e.to] == -1) {depth[e.to] = depth[u] + 1;q.push(e.to);} } }return depth[t] != -1;}int dfs(int v, int flow) {//dfs计算阻塞流if(v == t) return flow;49 行未改动cin >> n;p.resize(n); q.resize(n);for(int i = 0; i < n; i++) cin >> p[i];for(int i = 0; i < n; i++) cin >> q[i];int pcyc = 0, qcyc = 0;vector<int> pid = getcyc(p, pcyc);vector<int> qid = getcyc(q, qcyc);s = 0, t = 1;int pbase = 2, qbase = 2 + pcyc;mxnodes = qbase + qcyc;int base = 0;for(int i = 0; i < n; i++) {bool pisfixed = (p[i] == i);bool qisfixed = (q[i] == i);int u = pbase + pid[i];int v = qbase + qid[i];if(pisfixed && qisfixed) {//情况在上面都有解释base++;} else if(pisfixed && !qisfixed) {addedge(s, v, 1);14 行未改动