# bzoj 3532: [Sdoi2014]Lis

## Solution

$maxflow(T,v,c),maxflow(u,S,c)$ 再把这条边容量清零 , 最后再跑一边 $maxflow(S,T,inf)$ 就好了.

#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
int f;char c;
for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}
const int N=1550,inf=2e9;
int n,c[N],id[N],a[N],b[N],f[N];
inline void link(int x,int y,int z){
}
inline bool comp(const int &i,const int &j){return c[i]<c[j];}
inline bool bfs(int s,int t){
queue<int>Q;
for(int i=2*n+1;i>=0;i--)dep[i]=0;
Q.push(s);dep[s]=1;
while(!Q.empty()){
int x=Q.front();Q.pop();
if(dis[i]<=0 || dep[to[i]])continue;
int u=to[i];
dep[u]=dep[x]+1;Q.push(u);
if(u==t)return 1;
}
}
return dep[t];
}
inline int dfs(int x,int flow){
if(x==T || !flow)return flow;
int tot=0,t;
int u=to[i];
if(dis[i]<=0 || dep[u]!=dep[x]+1)continue;
t=dfs(u,min(flow,dis[i]));
dis[i]-=t;dis[i^1]+=t;tot+=t;flow-=t;
if(!flow)break;
}
if(!tot)dep[x]=-1;
}
inline int Dinic(int s,int t){
S=s;T=t;
int tot=0,x;
while(bfs(s,t)){
x=dfs(s,inf);
while(x)tot+=x,x=dfs(s,inf);
}
}
inline void work(){
int cnt=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)gi(a[i]);
for(int i=1;i<=n;i++)gi(b[i]);
for(int i=1;i<=n;i++)gi(c[i]),id[i]=i;
sort(id+1,id+n+1,comp);
int maxf=1;
for(int i=1;i<=n;i++){
f[i]=1;
for(int j=1;j<i;j++)if(a[j]<a[i])f[i]=max(f[i],f[j]+1);
maxf=max(maxf,f[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++)
}
int sum=Dinic(0,2*n+1);
for(int i=1;i<=n;i++){
int u=id[i],v=id[i]+n;
if(bfs(u,v))continue;
Dinic(2*n+1,v);Dinic(u,0);
ans[++cnt]=u;
}
sort(ans+1,ans+cnt+1);
printf("%d %d\n",sum,cnt);
printf("%d",ans[1]);
for(int i=2;i<=cnt;i++)printf(" %d",ans[i]);
}
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
int T;cin>>T;
while(T--)work(),T?puts(""):0;
return 0;
}


posted @ 2018-08-04 19:41  PIPIBoss  阅读(61)  评论(0编辑  收藏