标签:des http 使用 os io strong for ar
| Time Limit: 2000MS | Memory Limit: 32768K | |
| Total Submissions: 23114 | Accepted: 12103 |
Description

Input
Output
Sample Input
2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20
7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7
(3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5
(0)5 (1)2 (3)2 (4)1 (5)4
Sample Output
15 6
Hint
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 110
int p[maxn][maxn] , pre[maxn] , vis[maxn];
queue <int> q ;
void add(int u,int v,int w)
{
p[u][v] += w ;
}
int bfs(int s,int t,int n)
{
int u , v , i , min1 = INF ;
memset(vis,0,sizeof(vis));
vis[s] = 1 ;
while( !q.empty() )
q.pop();
q.push(s) ;
while( !q.empty() )
{
u = q.front();
q.pop();
if(u == t)
break;
for(i = 0 ; i <= n ; i++)
{
if( !vis[i] && p[u][i] )
{
pre[i] = u ;
vis[i] = 1 ;
q.push(i) ;
}
}
}
if( vis[t] )
{
for(i = t ; pre[i] != -1 ; i = pre[i])
if( p[pre[i]][i] < min1 )
min1 = p[ pre[i] ][i] ;
return min1 ;
}
return -1 ;
}
int main()
{
int n , np , nc , m , u , v , w , max_flow , i , j ;
char str[10] ;
while(scanf("%d %d %d %d", &n, &np, &nc, &m)!=EOF)
{
max_flow = 0 ;
memset(p,0,sizeof(p)) ;
while(m--)
{
scanf("%s", str);
sscanf(str,"(%d,%d)%d", &u, &v, &w);
add(u,v,w);
}
while(np--)
{
scanf("%s", str);
sscanf(str,"(%d)%d", &v, &w);
add(n,v,w);
}
while(nc--)
{
scanf("%s", str);
sscanf(str,"(%d)%d", &u, &w);
add(u,n+1,w);
}
memset(pre,-1,sizeof(pre));
while(1)
{
int k = bfs(n,n+1,n+1);
if(k == -1)
break;
max_flow += k ;
j = n+1 ;
for(i = pre[n+1] ; i != -1 ; i = pre[i])
{
p[i][j] -= k ;
p[j][i] += k ;
j = i ;
}
}
printf("%d\n", max_flow);
}
return 0;
}
poj459--Power Network(最大流EK、),布布扣,bubuko.com
标签:des http 使用 os io strong for ar
原文地址:http://blog.csdn.net/winddreams/article/details/38665209