1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define maxn 500 8 using namespace std; 9 int n,mm; 10 char g[maxn][maxn]; 11 const int inf=1<<30; 12 13 struct node 14 { 15 int x,y; 16 }m[maxn]; 17 18 struct node1 19 { 20 int x,y; 21 }h[maxn]; 22 23 int cap[maxn][maxn]; 24 int cost[maxn][maxn]; 25 int flow[maxn][maxn]; 26 int p[maxn]; 27 int s,t; 28 int main() 29 { 30 while(scanf("%d%d",&n,&mm)&&n&&mm) 31 { 32 memset(cap,0,sizeof(cap)); 33 memset(cost,0,sizeof(cost)); 34 int t1=0,t2=0; 35 for(int i=0; i
q; 73 int d[maxn]; 74 memset(flow,0,sizeof(flow)); 75 int c=0,f=0; 76 for(;;) 77 { 78 bool inq[maxn]; 79 for(int i=0; i<=t1+t2+1; i++) d[i]=(i==0?0:inf); 80 memset(inq,0,sizeof(inq)); 81 q.push(s); 82 while(!q.empty()) 83 { 84 int u=q.front();q.pop(); 85 inq[u]=false; 86 for(int v=0; v<=t1+t2+1; v++) if(cap[u][v]>flow[u][v] && d[v]>d[u]+cost[u][v]) 87 { 88 d[v]=d[u]+cost[u][v]; 89 p[v]=u; 90 if(!inq[v]) 91 { 92 inq[v]=true; 93 q.push(v); 94 } 95 } 96 } 97 if(d[t]==inf) break; 98 int a=inf; 99 for(int u=t; u!=s; u=p[u])100 {101 if(cap[p[u]][u]-flow[p[u]][u]