标签:images encode cst pat red int namespace inpu inf
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4854 | Accepted: 2241 |
Description
Input
Output
Sample Input
0 0 1 0 3 3 (0,1) (0,2) (1,2) 2 0 5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)
Sample Output
0 1 3 0 2
Hint
#include<queue> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int INF=1000000000; int head[111],dis[111],tot,st,ed,n,m; struct node { int to,next,w; } e[10086]; struct tc { int a,b; } po[10086]; void add(int u,int v,int w) { e[tot].to=v; e[tot].next=head[u]; e[tot].w=w; head[u]=tot++; } bool bfs() { queue<int>Q; memset(dis,-1,sizeof(dis)); Q.push(st); dis[st]=0; while(!Q.empty()) { int u=Q.front(); Q.pop(); for(int i=head[u]; ~i; i=e[i].next) { int v=e[i].to; if(dis[v]==-1&&e[i].w>0) { dis[v]=dis[u]+1; if(v==ed) return true; Q.push(v); } } } return false; } int dfs(int s,int low) { if(s==ed||low==0) return low; int ans=low,a; for(int i=head[s]; i+1; i=e[i].next) { int v=e[i].to; if(e[i].w>0&&dis[v]==dis[s]+1&&(a=dfs(v,min(e[i].w,ans)))) { ans-=a; e[i].w-=a; e[i^1].w+=a; if(!ans) return low; } } if(ans==low) dis[s]=-1; return low-ans; } void build() { memset(head,-1,sizeof(head)); tot=0; for(int i=1; i<=m; ++i) { add(po[i].a+n,po[i].b,INF); add(po[i].b+n,po[i].a,INF); } for(int i=0; i<n; ++i) add(i,i+n,1),add(i+n,i,0); } int main() { while(scanf("%d%d",&n,&m)!=EOF) { int a,b; for(int i=1; i<=m; ++i) { scanf(" (%d,%d)",&a,&b); po[i].a=a; po[i].b=b; } int ans=INF; for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) { st=i+n; ed=j; int ct=0; build(); while(bfs()) ct+=dfs(st,INF); ans=min(ct,ans); } if(ans==INF) printf("%d\n",n); else printf("%d\n",ans); } }
标签:images encode cst pat red int namespace inpu inf
原文地址:http://www.cnblogs.com/mfys/p/7351698.html