#include<iostream>
#include<cstdio>
#include<cstring>
#define inf 0x7fffffff
#define T 1001
using namespace std;
int head[1005],q[1005],h[1005];
int m,n,cnt=1,ans;
struct data{int to,next,v;}e[500001];
void ins(int u,int v,int w)
{e[++cnt].to=v;e[cnt].next=head[u];e[cnt].v=w;head[u]=cnt;}
void insert(int u,int v,int w)
{ins(u,v,w);ins(v,u,0);}
bool bfs()
{
int t=0,w=1,i,now;
memset(h,-1,sizeof(h));
q[0]=0;h[0]=0;
while(t<w)
{
now=q[t];t++;i=head[now];
while(i)
{
if(e[i].v&&h[e[i].to]==-1)
{
h[e[i].to]=h[now]+1;
q[w++]=e[i].to;
}
i=e[i].next;
}
}
return h[T]==-1? 0:1;
}
int dfs(int x,int f)
{
if(x==T)return f;
int w,used=0,i;
i=head[x];
while(i)
{
if(e[i].v&&h[e[i].to]==h[x]+1)
{
w=f-used;
w=dfs(e[i].to,min(w,e[i].v));
e[i].v-=w;
e[i^1].v+=w;
used+=w;
if(used==f)return f;
}
i=e[i].next;
}
if(!used)h[x]=-1;
return used;
}
void dinic(){while(bfs())ans-=dfs(0,inf);}
int main()
{
//freopen("roundtable.in","r",stdin);
//freopen("roundtable.out","w",stdout);
scanf("%d%d",&m,&n);int x;
for(int i=1;i<=m;i++){scanf("%d",&x);insert(0,i,x);ans+=x;}
for(int i=1;i<=n;i++){scanf("%d",&x);insert(m+i,T,x);}
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
insert(i,m+j,1);
dinic();
if(ans){printf("0");return 0;}
printf("1\n");
for(int i=1;i<=m;i++)
{
int t=head[i];
while(t)
{
if(!e[t].v)printf("%d ",e[t].to-m);
t=e[t].next;
}
printf("\n");
}
return 0;
}
cojs.TK怎么找不到网址。。
http://www.cojs.tk/cogs/index.php
谢谢