记录编号 |
149190 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[网络流24题] 圆桌聚餐 |
最终得分 |
100 |
用户昵称 |
OIdiot |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.113 s |
提交时间 |
2015-02-20 15:09:56 |
内存使用 |
23.20 MiB |
显示代码纯文本
/*
Machine: lenovo E440
System: Ubuntu Kylin 14.04
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <ctime>
#include <algorithm>
typedef long long LL;
using namespace std;
#define SpeedUp ios::sync_with_stdio(false)
#define Judge
//#define Debug
#define MAXN (450)
#define MAXM (2000002)
#define INF (0x7fffffff)
const double PI=acos(-1);
const int ZCY=1000000007;
inline int getint(){
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*10+ch-'0';ch=getchar();}
return x*f;
}
inline void outputint(int x){
char ch[12];
int cnt=0;
if(x==0) {putchar('0'); putchar(10);return;}
if(x<0) {putchar('-'); x=-x;}
while(x) ch[++cnt]=x%10,x/=10;
while(cnt) putchar(ch[cnt--]+48);
putchar(32);
}
#define print(x) outputint(x)
#define read(x) x=getint()
struct Edge{
int v,next,flow;
Edge(int _v=0,int _n=0,int _f=0):
v(_v),next(_n),flow(_f){}
}E[MAXM];
int G[MAXN],dist[MAXN],cur[MAXN];
int N,M,tot,S,T,tot_staff,maxflow;
inline void Ins(int u,int v,int f){
E[++tot]=Edge(v,G[u],f); G[u]=tot;
E[++tot]=Edge(u,G[v],0); G[v]=tot;
}
void init(){
int c;
#ifdef Judge
freopen("roundtable.in","r",stdin);
freopen("roundtable.out","w",stdout);
// SpeedUp;
#endif
read(N),read(M);
S=0,T=N+M+1,tot=1;
for(int i=1;i<=N;i++){
read(c);
tot_staff+=c;
Ins(S,i,c);
}
for(int i=1;i<=M;i++){
read(c);
Ins(N+i,T,c);
}
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
Ins(i,N+j,1);
}
queue<int> Q;
bool BFS(){
while(!Q.empty()) Q.pop();
memset(dist,-1,sizeof(dist));
Q.push(S);
dist[S]=0;
while(!Q.empty()){
int k=Q.front();
Q.pop();
for(int u=G[k];u;u=E[u].next){
int v=E[u].v;
if(E[u].flow && dist[v]==-1){
dist[v]=dist[k]+1;
Q.push(v);
}
}
}
return dist[T]!=-1;
}
int DFS(int x,int f){
if(x==T) return f;
int cnt=f;
for(int u=cur[x];u;u=E[u].next){
int v=E[u].v;
if(E[u].flow && dist[v]==dist[x]+1){
int w=DFS(v,min(f,E[u].flow));
E[u].flow-=w;
E[u^1].flow+=w;
if(E[u].flow) cur[x]=u;
f-=w;
if(f==0) return cnt;
}
}
if(f==cnt) dist[x]=-1;
return cnt-f;
}
void dinic(){
while(BFS()){
for(int i=S;i<=T;i++)
cur[i]=G[i];
maxflow+=DFS(S,INF);
}
}
void work(){
dinic();
if(maxflow<tot_staff){
print(0);
puts("");
return;
}
print(1),puts("");
for(int x=1;x<=N;x++){
for(int u=G[x];u;u=E[u].next){
int v=E[u].v;
if(E[u].flow==0 && v>N)
print(v-N);
}
puts("");
}
}
int main(){
init();
work();
#ifdef Debug
cout<<"Time Used : "<<(double)clock()/CLOCKS_PER_SEC<<" s."<<endl;
cout<<"Memory Used : "<<(double)(sizeof())/1048576<<" MB."<<endl;
#endif
return 0;
}