hdu 4411 Arrest
解题报告说是上下界费用流,我这里用的也是上下界的方法,不用上下界也是一样的,把必经过的边的费用变成-inf,那么在求最小费用流时程序一定会经过这条边,同样起到了限制下界的作用,这样更好理解~#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define MC(a,b) memcpy(a,b,sizeof(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 222;
const int add = 111;
const int head = 220;
const int end = 221;
struct zz
{
int from;
int to;
int c;
int cost;
int id;
}zx;
vector<zz>g[maxn];
int n,m,k;
int d[maxn][maxn];
int way[maxn];
bool inq[maxn];
int back[maxn];
void floyd()
{
for(int k=0;k<=n;k++)
{
for(int i=0;i<=n;i++)
{
if(d[i][k]==inf) continue;
for(int j=0;j<=n;j++)
{
if(d[k][j]==inf) continue;
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
}
return ;
}
void link(int now,int to,int c,int cost,int bc=0)
{
zx.from=now;zx.to=to;zx.c=c;zx.cost=cost;zx.id=g[zx.to].size();
g[zx.from].pb(zx);
swap(zx.from,zx.to);zx.c=bc;zx.cost=-cost;zx.id=g[zx.to].size()-1;
g[zx.from].pb(zx);
return ;
}
bool spfa()
{
for(int i=0;i<maxn;i++) way[i]=inf;
MM(back,-1);
queue<int>q;
MM(inq,false);
inq[head]=true;
q.push(head);
way[head]=0;
int now,to,temp;
while(!q.empty())
{
now = q.front();
q.pop();
for(int i=0;i<g[now].size();i++)
{
to = g[now][i].to;
if(g[now][i].c>0)
{
temp = way[now]+g[now][i].cost;
if(temp < way[to])
{
way[to]=temp;
back[to]=g[now][i].id;
if(!inq[to])
{
inq[to]=true;
q.push(to);
}
}
&nb
补充:软件开发 , C++ ,