标签:space ops efi har inpu oid following ace define
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 8356 | Accepted: 2696 | Special Judge |
Description
Input
Output
Sample Input
3 6 1 2 3 4 2 1 1 2 1 1 3 2 1 2 3 1 2 3
Sample Output
5 3 1 + 2 - 2 +
Source
思路:
最小点权覆盖;
来,上代码:
#include <queue> #include <cstdio> #include <cstring> #include <iostream> #define INF 0x7ffffff using namespace std; struct EdgeType { int v,e,f; }; struct EdgeType edge[5000<<5]; int n,m,vout[105],vin[105],s,t; int head[505],deep[505],cnt=1,ans; bool if_[505]; char Cget; inline void in(int &now) { now=0,Cget=getchar(); while(Cget>‘9‘||Cget<‘0‘) Cget=getchar(); while(Cget>=‘0‘&&Cget<=‘9‘) { now=now*10+Cget-‘0‘; Cget=getchar(); } } inline void edge_add(int u,int v,int f) { edge[++cnt].v=v,edge[cnt].f=f,edge[cnt].e=head[u],head[u]=cnt; edge[++cnt].v=u,edge[cnt].f=0,edge[cnt].e=head[v],head[v]=cnt; } bool BFS() { for(int i=s;i<=t;i++) deep[i]=-1; queue<int>que;que.push(s);deep[s]=0; while(!que.empty()) { int now=que.front(); for(int i=head[now];i;i=edge[i].e) { if(deep[edge[i].v]<0&&edge[i].f>0) { deep[edge[i].v]=deep[now]+1; if(edge[i].v==t) return true; que.push(edge[i].v); } } que.pop(); } return false; } int flowing(int now,int flow) { if(now==t||flow==0) return flow; int oldflow=0; for(int i=head[now];i;i=edge[i].e) { if(deep[edge[i].v]!=deep[now]+1||edge[i].f==0) continue; int pos=flowing(edge[i].v,min(flow,edge[i].f)); flow-=pos; oldflow+=pos; edge[i].f-=pos; edge[i^1].f+=pos; if(flow==0) return oldflow; } if(oldflow==0) deep[now]=-1; return oldflow; } void check(int now) { if_[now]=true; for(int i=head[now];i;i=edge[i].e) { if(!edge[i].f||if_[edge[i].v]) continue; check(edge[i].v); } } int main() { in(n),in(m); s=0,t=n+n+1; for(int i=1;i<=n;i++) { in(vout[i]); edge_add(i+n,t,vout[i]); } for(int i=1;i<=n;i++) { in(vin[i]); edge_add(s,i,vin[i]); } int u,v; for(int i=1;i<=m;i++) { in(u),in(v); edge_add(u,v+n,INF); } while(BFS()) ans+=flowing(s,INF); cout<<ans;ans=0; putchar(‘\n‘);check(s); for(int i=1;i<=n;i++) { if(!if_[i]) ans++; if(if_[i+n]) ans++; } cout<<ans;putchar(‘\n‘); for(int i=1;i<=n;i++) { if(!if_[i]) printf("%d -\n",i); if(if_[i+n]) printf("%d +\n",i); } return 0; }
AC日记——Destroying The Graph poj 2125
标签:space ops efi har inpu oid following ace define
原文地址:http://www.cnblogs.com/IUUUUUUUskyyy/p/6505342.html