记录一个菜逼的成长。。
二分图匹配,由于一个代表只能一桌,同一个代表团不能坐同一桌
所以代表团跟桌的流量设为1
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define cl(a,b) memset(a,b,sizeof(a))
#define clr clear()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int MAX_V = 1000 + 10;
struct edge{
int to,cap,rev,flow;
edge(){}
edge(int _to,int _cap,int _rev,int _flow):to(_to),cap(_cap),rev(_rev),flow(_flow){}
};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add(int from,int to,int cap,int flow = 0)
{
G[from].push_back(edge(to,cap,G[to].size(),0));
G[to].push_back(edge(from,0,G[from].size()-1,0));
}
void bfs(int s)
{
memset(level,-1,sizeof(level));
queue<int>que;
level[s] = 0;
que.push(s);
while(!que.empty()){
int f = que.front();
que.pop();
for( int i = 0; i < G[f].size(); i++ ){
edge &e = G[f][i];
if(e.cap > 0 && level[e.to] == -1){
level[e.to] = level[f] + 1;
que.push(e.to);
}
}
}
}
int dfs(int v,int t,int f)
{
if(v == t)return f;
for( int &i = iter[v]; i < G[v].size(); i++ ){
edge &e = G[v][i];
if(e.cap > 0 && level[v] < level[e.to]){
int d = dfs(e.to,t,min(e.cap,f));
if(d > 0){
e.cap -= d;e.flow += d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int max_flow(int s,int t)
{
int flow = 0;
for(;;){
bfs(s);
if(level[t] == -1)return flow;
memset(iter,0,sizeof(iter));
int f;
while((f = dfs(s,t,INF)) > 0)
flow += f;
}
}
int vis[MAX_V];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int s = 0,t = n + m + 1;
int sum = 0;
for( int i = 1; i <= n; i++ ){
int x;scanf("%d",&x);
sum += x;
add(s,i,x);
}
for( int i = 1; i <= n; i++ ){
for( int j = 1; j <= m; j++ ){
add(i,j+n,1);
}
}
for( int i = 1; i <= m; i++ ){
int x;scanf("%d",&x);
add(i+n,t,x);
}
int ret = max_flow(s,t);
if(ret < sum){
puts("0");return 0;
}
puts("1");
for( int i = 1; i <= n; i++ ){
for( int j = 0; j < G[i].size(); j++ ){
if(G[i][j].to > n && G[i][j].cap == 0){
printf("%d ",G[i][j].to - n);
}
}
puts("");
}
return 0;
}