1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| #include<bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #else #define debug(...) void(0) #endif
inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'|| ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second
#define N 400010
namespace Flow { #define int long long struct mf_graph { struct node { int x, y, z, n; }; vector<node>d; vector<int>h, H, dep; queue<int>q; int k; int u, v, w, S, T, ans=0; void reset(int n) { h.resize(n+5); k=1; d.resize(2); H.resize(n+5); dep.resize(n+5); } void cun(int x, int y, int z) { ++k; d.pb({x, y, z, h[x]}); d[k].n=h[x]; h[x]=k; } int add_edge(int x, int y, int z) { cun(x, y, z); cun(y, x, 0); return k-1; } int get_edge(int k) { return d[k].z; } int bfs() { while(!q.empty()) q.pop(); fill(dep.begin(), dep.end(), -1); h=H; dep[S]=1; q.push(S); while(!q.empty()) { u=q.front(); q.pop(); for(int g=h[u]; g; g=d[g].n) { v=d[g].y; w=d[g].z; if(w<=0 || dep[v]!=-1) continue; dep[v]=dep[u]+1; q.push(v); } } return dep[T]!=-1; } int dfs(int x, int w) { if(x==T) return w; if(!w) return 0; int ans=0, s; for(int &i=h[x]; i; i=d[i].n) { int y=d[i].y, z=d[i].z; if(dep[y]!=dep[x]+1) continue; if(z<=0) continue; s=dfs(y, min(w, z)); ans+=s; w-=s; d[i].z-=s; d[i^1].z+=s; if(!w) break; } return ans; } int flow(int SS, int TT) { S=SS; T=TT; H=h; ans=0; while(bfs()) ans+=dfs(S, 1e18); return ans; } }; #undef int } using namespace Flow; int n, m, i, j, k, T, S, tot; int ans, L[N], R[N], a[N], p1[N], p2[N], qr[N];
signed main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif
mf_graph G; G.reset(4e5); n = read(); S = 1; T = tot = 2; for(i=1; i<=1e5; ++i) L[i]=++tot, R[i]=++tot, qr[i]=G.add_edge(L[i], R[i], 1); for(i=1; i<=n; ++i) { p1[i]=++tot, p2[i]=++tot; G.add_edge(S, p1[i], 1); G.add_edge(p2[i], T, 1); } for(i=1; i<=n; ++i) { a[i]=read(); G.add_edge(p1[i], L[a[i]], 1); G.add_edge(R[a[i]], p2[i], 1); } ans = G.flow(S, T);
for(i=1; i<=n; ++i) { a[i]=read(); G.add_edge(p1[i], L[a[i]], 1);
} for(i=1; i<=n; ++i) { a[i]=read();
G.add_edge(R[a[i]], p2[i], 1); } ans += G.flow(S, T); printf("%d\n", ans); for(i=1; i<=1e5; ++i) { k = G.get_edge(qr[i]); if(!k) printf("%d ", i); } return 0; }
|