[AHOI2014]支线剧情 bzoj3876

裸的上下界费用流
#include
#include
using namespace std;
const int maxn=50000,inf=1<<30;
int head[maxn],dist[maxn],s,t,prev[maxn],pree[maxn],ans,n,que[maxn];
bool inq[maxn];
struct edge{
	int to,next,c,f;
}g[maxn];
int num=1;
void adde(int u,int v,int f,int c){
	g[++num].to=v;g[num].f=f;g[num].c=c; g[num].next=head[u];head[u]=num;
	g[++num].to=u;g[num].f=0;g[num].c=-c;g[num].next=head[v];head[v]=num;
}
bool spfa(){
	for(int i=0;i<=n+1;i++) dist[i]=inf;
	dist[s]=0;
	que[1]=s;
	inq[s]=1;
	int he=1,ta=1;
	while(he<=ta){
		int x=que[he++];
		for(int i=head[x];i;i=g[i].next){
			int node=g[i].to;
			if(g[i].f&&dist[node]>dist[x]+g[i].c){
				dist[node]=dist[x]+g[i].c;
				prev[node]=x;pree[node]=i;
				if(!inq[node]){
					inq[node]=1;
					que[++ta]=node;
				}
			}
		}
		inq[x]=0;
	}
	return dist[t]

你可能感兴趣的:([AHOI2014]支线剧情 bzoj3876)