xfstart07
Get busy living or get busy dying
#include < cstdio >
#include
< cstring >
using   namespace  std;

const   int  INF = 0x7FFFFFFF ;
int  N,M;
int  ans;
int  pre[ 200 ];
bool  vis[ 200 ];
int  g[ 200 ][ 200 ];
bool  BFS()
{
    
int  h,t,que[ 200 ];
    memset(vis,
0 , sizeof (vis));
    h
= t = 1 ; que[ 1 ] = 0 ;
    vis[
0 ] = 1 ; pre[ 0 ] = 0 ;
    
while (h <= t){
        
int  x = que[h ++ ];
        
for ( int  i = 1 ;i <= N + N + 1 ; ++ i)
            
if ( ! vis[i] && g[x][i]){
                vis[i]
= 1 ;
                que[
++ t] = i;
                pre[i]
= x;
                
if (i == N)  return   1 ;
            }
    }
    
return   0 ;
}
void  Find()
{
    
int  best = INF;
    
for ( int  i = N;i > 0 ;i = pre[i])
        
if (g[pre[i]][i] < best)
            best
= g[pre[i]][i];
    ans
+= best;
    
for ( int  i = N;i > 0 ;i = pre[i]){
        g[pre[i]][i]
-= best;
        
if (g[i][pre[i]] >= INF - best)
            g[i][pre[i]]
= INF;
        
else  g[i][pre[i]] += best;
    }
}
int  main()
{
    
int  t; scanf( " %d " , & t);
    
while (t -- ){
        scanf(
" %d%d " , & N, & M);
        
if (N == 0 ){ printf( " Max! " );  continue ; }
        memset(g,
0 , sizeof (g));
        
for ( int  i = 1 ;i < N; ++ i)
            scanf(
" %d " , & g[N + 1 + i][i]);
        
bool  flag = 0 ;
        
for ( int  i = 1 ;i <= M; ++ i){
            
int  x,y; scanf( " %d%d " , & x, & y);
            
if ((x == 0 && y == N) || (x == N && y == 0 )) flag = 1 ;
            g[x][N
+ 1 + y] = g[y][N + 1 + x] = INF;
        }
        
if (flag){ printf( " Max! " );  continue ; }
        g[N
+ 1 + N][N] = INF;
        ans
= 0 ;
        
while (BFS())
            Find();
        
if (ans) printf( " %d\n " ,ans);
        
else  printf( " Min!\n " );
    }
    
return   0 ;
}





posted on 2009-08-11 08:55 xfstart07 阅读(131) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理